Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,27 @@
|
|
1 |
-
import os
|
2 |
-
os.system('sh setup.sh')
|
3 |
import gradio as gr
|
4 |
-
from
|
5 |
-
|
6 |
-
# Initialize the Hugging Face
|
7 |
-
|
8 |
-
|
9 |
-
def generate_response(
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
stream=True,
|
25 |
-
temperature=temperature,
|
26 |
-
top_p=top_p,
|
27 |
-
):
|
28 |
-
token = token_message.choices[0].delta.content
|
29 |
-
response += token
|
30 |
-
yield response
|
31 |
|
32 |
def chat_interface(user_input, history, system_message, max_tokens, temperature, top_p):
|
33 |
-
|
34 |
-
response = "".join([token for token in response_generator])
|
35 |
history.append((user_input, response))
|
36 |
return history, history
|
37 |
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline, set_seed
|
3 |
+
|
4 |
+
# Initialize the Hugging Face pipeline
|
5 |
+
generator = pipeline('text-generation', model='redael/model_udc')
|
6 |
+
|
7 |
+
def generate_response(prompt, max_length=100, num_beams=5, temperature=0.5, top_p=0.9, repetition_penalty=4.0):
|
8 |
+
# Prepare the prompt
|
9 |
+
prompt = f"User: {prompt}\nAssistant:"
|
10 |
+
responses = generator(prompt, max_length=max_length, num_return_sequences=1, num_beams=num_beams, temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty)
|
11 |
+
response = responses[0]['generated_text']
|
12 |
+
|
13 |
+
# Post-processing to clean up the response
|
14 |
+
response = response.split("Assistant:")[-1].strip()
|
15 |
+
response_lines = response.split('\n')
|
16 |
+
clean_response = []
|
17 |
+
for line in response_lines:
|
18 |
+
if "User:" not in line and "Assistant:" not in line:
|
19 |
+
clean_response.append(line)
|
20 |
+
response = ' '.join(clean_response)
|
21 |
+
return response.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def chat_interface(user_input, history, system_message, max_tokens, temperature, top_p):
|
24 |
+
response = generate_response(user_input, max_length=max_tokens, temperature=temperature, top_p=top_p)
|
|
|
25 |
history.append((user_input, response))
|
26 |
return history, history
|
27 |
|