OjciecTadeusz commited on
Commit
dc3ffec
·
verified ·
1 Parent(s): 26cfd4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -105,36 +105,31 @@ def chat_interface(message, chat_history):
105
  return chat_history
106
 
107
  try:
108
- # Format the message history in the OpenAI style
109
  messages = []
110
  for msg in chat_history:
111
  messages.append({"role": "user", "content": msg[0]})
112
  if msg[1] is not None:
113
  messages.append({"role": "assistant", "content": msg[1]})
114
 
115
- # Add the current message
116
  messages.append({"role": "user", "content": message})
117
 
118
- # Get response
119
  response = generate_response(messages)
120
 
121
- # Update history in the new format
122
  chat_history.append((message, response))
123
  return chat_history
124
  except Exception as e:
125
  chat_history.append((message, f"Error: {str(e)}"))
126
  return chat_history
127
 
128
- # Create Gradio interface with new message format
129
- demo = gr.ChatInterface(
130
- fn=chat_interface,
131
  title="Qwen2.5-Coder-32B Chat",
132
  description="Chat with Qwen2.5-Coder-32B model via Hugging Face Inference API",
133
- examples=["Hello! Can you help me with coding?",
134
- "Write a simple Python function to calculate factorial"],
135
- retry_btn="Retry",
136
- undo_btn="Undo last message",
137
- clear_btn="Clear conversation",
138
  )
139
 
140
  # Mount both FastAPI and Gradio
 
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
  title="Qwen2.5-Coder-32B Chat",
128
  description="Chat with Qwen2.5-Coder-32B model via Hugging Face Inference API",
129
+ examples=[
130
+ "Hello! Can you help me with coding?",
131
+ "Write a simple Python function to calculate factorial"
132
+ ]
 
133
  )
134
 
135
  # Mount both FastAPI and Gradio