zqu2004 commited on
Commit
5793084
1 Parent(s): dce5482

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
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
- for message in client.text_generation(
36
- prompt="\n".join([m["content"] for m in messages]),
37
- max_new_tokens=max_tokens,
38
- stream=True,
39
- temperature=temperature,
40
- top_p=top_p,
41
- ):
42
- token = message.token.text
43
-
44
- response += token
45
- yield response
 
 
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()