OjciecTadeusz commited on
Commit
d98612c
·
verified ·
1 Parent(s): c0b6ccf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -25
app.py CHANGED
@@ -100,35 +100,20 @@ def generate_response(messages):
100
 
101
  return result[0]["generated_text"]
102
 
103
- def chat_interface(message, chat_history):
104
- if message.strip() == "":
105
- return chat_history
106
-
107
- try:
108
- messages = []
109
- for msg in chat_history:
110
- messages.append({"role": "user", "content": msg[0]})
111
- if msg[1] is not None:
112
- messages.append({"role": "assistant", "content": msg[1]})
113
-
114
- messages.append({"role": "user", "content": message})
115
-
116
- response = generate_response(messages)
117
-
118
- chat_history.append((message, response))
119
- return chat_history
120
- except Exception as e:
121
- chat_history.append((message, f"Error: {str(e)}"))
122
- return chat_history
123
 
124
  # Create Gradio interface
125
  demo = gr.Chatbot(
126
  chat_interface,
127
- #description="Chat with Qwen2.5-Coder-32B model via Hugging Face Inference API",
128
- examples=[
129
- "Hello! Can you help me with coding?",
130
- "Write a simple Python function to calculate factorial"
131
- ]
132
  )
133
 
134
  # Mount both FastAPI and Gradio
 
100
 
101
  return result[0]["generated_text"]
102
 
103
+ def chat_interface(messages):
104
+ chat_history = []
105
+ for message in messages:
106
+ try:
107
+ response = generate_response([{"role": "user", "content": message}])
108
+ chat_history.append((message, response))
109
+ except Exception as e:
110
+ chat_history.append((message, f"Error: {str(e)}"))
111
+ return chat_history
 
 
 
 
 
 
 
 
 
 
 
112
 
113
  # Create Gradio interface
114
  demo = gr.Chatbot(
115
  chat_interface,
116
+ type="messages"
 
 
 
 
117
  )
118
 
119
  # Mount both FastAPI and Gradio