hsuwill000 commited on
Commit
6ed2caf
·
verified ·
1 Parent(s): e69a5b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -15,7 +15,7 @@ def respond(message, history):
15
  # Combine the entire conversation history
16
  input_text = message
17
  if history:
18
- input_text = "\n".join([f"User: {h['user']}\nBot: {h['bot']}" for h in history]) + f"\nUser: {message}"
19
 
20
  # Generate response
21
  response = pipe(
@@ -29,12 +29,12 @@ def respond(message, history):
29
  reply = response[0]['generated_text'].strip()
30
 
31
  # Update history
32
- history.append({"user": message, "bot": reply})
33
  return history
34
 
35
  except Exception as e:
36
  print(f"Error: {e}")
37
- return history + [{"user": message, "bot": "Sorry, something went wrong. Please try again."}]
38
 
39
  # Set up Gradio chat interface
40
  demo = gr.ChatInterface(
@@ -42,9 +42,7 @@ demo = gr.ChatInterface(
42
  title="Qwen2.5-1.5B-Instruct-openvino",
43
  description="Chat with Qwen2.5-1.5B-Instruct-openvino model.",
44
  examples=["Hello!", "Tell me a joke.", "Explain quantum computing."],
45
- retry_btn=None,
46
- undo_btn=None,
47
- clear_btn="Clear History",
48
  )
49
 
50
  if __name__ == "__main__":
 
15
  # Combine the entire conversation history
16
  input_text = message
17
  if history:
18
+ input_text = "\n".join([f"User: {h[0]}\nBot: {h[1]}" for h in history]) + f"\nUser: {message}"
19
 
20
  # Generate response
21
  response = pipe(
 
29
  reply = response[0]['generated_text'].strip()
30
 
31
  # Update history
32
+ history.append((message, reply))
33
  return history
34
 
35
  except Exception as e:
36
  print(f"Error: {e}")
37
+ return history + [(message, "Sorry, something went wrong. Please try again.")]
38
 
39
  # Set up Gradio chat interface
40
  demo = gr.ChatInterface(
 
42
  title="Qwen2.5-1.5B-Instruct-openvino",
43
  description="Chat with Qwen2.5-1.5B-Instruct-openvino model.",
44
  examples=["Hello!", "Tell me a joke.", "Explain quantum computing."],
45
+ clear_btn="Clear History", # 仅保留 clear_btn
 
 
46
  )
47
 
48
  if __name__ == "__main__":