Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,9 @@ def respond(
|
|
20 |
temperature,
|
21 |
top_p,
|
22 |
):
|
|
|
|
|
|
|
23 |
messages = [{"role": "system", "content": system_message}]
|
24 |
|
25 |
for val in history:
|
@@ -32,20 +35,22 @@ def respond(
|
|
32 |
|
33 |
response = ""
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
46 |
|
47 |
def update_textbox(prompt):
|
48 |
-
return prompt
|
49 |
|
50 |
with gr.Blocks() as demo:
|
51 |
chatbot = gr.Chatbot()
|
|
|
20 |
temperature,
|
21 |
top_p,
|
22 |
):
|
23 |
+
if not message:
|
24 |
+
return ""
|
25 |
+
|
26 |
messages = [{"role": "system", "content": system_message}]
|
27 |
|
28 |
for val in history:
|
|
|
35 |
|
36 |
response = ""
|
37 |
|
38 |
+
try:
|
39 |
+
for message in client.text_generation(
|
40 |
+
prompt="\n".join([m["content"] for m in messages]),
|
41 |
+
max_new_tokens=max_tokens,
|
42 |
+
stream=True,
|
43 |
+
temperature=temperature,
|
44 |
+
top_p=top_p,
|
45 |
+
):
|
46 |
+
token = message.token.text
|
47 |
+
response += token
|
48 |
+
yield response
|
49 |
+
except Exception as e:
|
50 |
+
yield f"An error occurred: {str(e)}"
|
51 |
|
52 |
def update_textbox(prompt):
|
53 |
+
return gr.update(value=prompt)
|
54 |
|
55 |
with gr.Blocks() as demo:
|
56 |
chatbot = gr.Chatbot()
|