mcwm04 commited on
Commit
4d2cc6f
·
verified ·
1 Parent(s): 12ec9f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -5,20 +5,18 @@ from huggingface_hub import InferenceClient
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
  def respond(message, history):
8
- # Prepare the prompt with conversation history
9
  messages = [{"role": "system", "content": "You are a helpful and witty AI assistant."}]
10
 
11
- for val in history:
12
- if val[0]:
13
- messages.append({"role": "user", "content": val[0]})
14
- if val[1]:
15
- messages.append({"role": "assistant", "content": val[1]})
16
 
17
  messages.append({"role": "user", "content": message})
18
 
19
  response = ""
20
 
21
- # Stream the response from the model
22
  for message in client.chat_completion(
23
  messages,
24
  max_tokens=512,
@@ -30,13 +28,12 @@ def respond(message, history):
30
  response += token
31
  yield response
32
 
33
- # Create the Gradio UI
34
  demo = gr.ChatInterface(
35
- respond,
36
  title="My Simple Chatbot",
37
  description="Ask me anything! This bot is running on Hugging Face Spaces.",
38
- examples=["What's a cool fact about space?", "Write a short poem about coffee."],
39
- theme="soft"
40
  )
41
 
42
  if __name__ == "__main__":
 
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
  def respond(message, history):
 
8
  messages = [{"role": "system", "content": "You are a helpful and witty AI assistant."}]
9
 
10
+ # Gradio history comes as a list of lists: [[user, bot], [user, bot]]
11
+ for user_msg, bot_msg in history:
12
+ messages.append({"role": "user", "content": user_msg})
13
+ messages.append({"role": "assistant", "content": bot_msg})
 
14
 
15
  messages.append({"role": "user", "content": message})
16
 
17
  response = ""
18
 
19
+ # Stream the response
20
  for message in client.chat_completion(
21
  messages,
22
  max_tokens=512,
 
28
  response += token
29
  yield response
30
 
31
+ # Create the Gradio UI - Removed 'theme' to fix the TypeError
32
  demo = gr.ChatInterface(
33
+ fn=respond,
34
  title="My Simple Chatbot",
35
  description="Ask me anything! This bot is running on Hugging Face Spaces.",
36
+ examples=["What's a cool fact about space?", "Write a short poem about coffee."]
 
37
  )
38
 
39
  if __name__ == "__main__":