vedaco commited on
Commit
79bbbdb
·
verified ·
1 Parent(s): 7591fe1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -1,4 +1,4 @@
1
- """Gradio App for Veda Programming Assistant - Fixed for Gradio 6.2.0"""
2
 
3
  import gradio as gr
4
  import tensorflow as tf
@@ -124,6 +124,9 @@ def generate_response(user_input: str, temperature: float = 0.7, max_tokens: int
124
 
125
  response = clean_response(response)
126
 
 
 
 
127
  conversation_history.append({
128
  'user': user_input,
129
  'assistant': response
@@ -139,18 +142,22 @@ def generate_response(user_input: str, temperature: float = 0.7, max_tokens: int
139
  return f"Error: {str(e)}"
140
 
141
 
142
- def respond(message, chat_history, temperature, max_tokens):
143
- """Chat function - returns tuple format"""
144
  if not message or not message.strip():
145
- return "", chat_history if chat_history else []
146
 
147
  bot_message = generate_response(message, temperature, max_tokens)
148
 
149
- if chat_history is None:
150
- chat_history = []
 
 
 
 
 
151
 
152
- chat_history.append((message, bot_message))
153
- return "", chat_history
154
 
155
 
156
  def feedback_good():
@@ -215,7 +222,7 @@ initialize()
215
  print("Initialization complete!")
216
 
217
 
218
- # Create Gradio interface - NO type parameter
219
  with gr.Blocks(title="Veda Programming Assistant") as demo:
220
 
221
  gr.Markdown("""
@@ -227,10 +234,10 @@ with gr.Blocks(title="Veda Programming Assistant") as demo:
227
  with gr.Tabs():
228
 
229
  with gr.TabItem("💬 Chat"):
230
- # Simple Chatbot without type parameter
231
  chatbot = gr.Chatbot(
232
  label="Conversation",
233
- height=400
 
234
  )
235
 
236
  with gr.Row():
@@ -265,7 +272,6 @@ with gr.Blocks(title="Veda Programming Assistant") as demo:
265
 
266
  feedback_msg = gr.Textbox(label="Status", lines=1, interactive=False)
267
 
268
- # Event handlers
269
  send_btn.click(
270
  respond,
271
  inputs=[msg, chatbot, temperature, max_tokens],
@@ -320,12 +326,8 @@ with gr.Blocks(title="Veda Programming Assistant") as demo:
320
  refresh_btn = gr.Button("🔄 Refresh Statistics")
321
  refresh_btn.click(get_stats, outputs=stats_out)
322
 
323
- gr.Markdown("""
324
- ---
325
- **Veda Programming Assistant** - Learning from every conversation!
326
- """)
327
 
328
 
329
- # Launch the app
330
  if __name__ == "__main__":
331
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ """Gradio App for Veda Programming Assistant - Gradio 6.2.0"""
2
 
3
  import gradio as gr
4
  import tensorflow as tf
 
124
 
125
  response = clean_response(response)
126
 
127
+ if not response:
128
+ response = "I'm not sure how to respond to that. Could you try rephrasing?"
129
+
130
  conversation_history.append({
131
  'user': user_input,
132
  'assistant': response
 
142
  return f"Error: {str(e)}"
143
 
144
 
145
+ def respond(message, history, temperature, max_tokens):
146
+ """Chat function using messages format for Gradio 6.x"""
147
  if not message or not message.strip():
148
+ return "", history if history else []
149
 
150
  bot_message = generate_response(message, temperature, max_tokens)
151
 
152
+ if history is None:
153
+ history = []
154
+
155
+ # Gradio 6.x requires messages format
156
+ new_history = list(history)
157
+ new_history.append({"role": "user", "content": message})
158
+ new_history.append({"role": "assistant", "content": bot_message})
159
 
160
+ return "", new_history
 
161
 
162
 
163
  def feedback_good():
 
222
  print("Initialization complete!")
223
 
224
 
225
+ # Create Gradio interface
226
  with gr.Blocks(title="Veda Programming Assistant") as demo:
227
 
228
  gr.Markdown("""
 
234
  with gr.Tabs():
235
 
236
  with gr.TabItem("💬 Chat"):
 
237
  chatbot = gr.Chatbot(
238
  label="Conversation",
239
+ height=400,
240
+ value=[]
241
  )
242
 
243
  with gr.Row():
 
272
 
273
  feedback_msg = gr.Textbox(label="Status", lines=1, interactive=False)
274
 
 
275
  send_btn.click(
276
  respond,
277
  inputs=[msg, chatbot, temperature, max_tokens],
 
326
  refresh_btn = gr.Button("🔄 Refresh Statistics")
327
  refresh_btn.click(get_stats, outputs=stats_out)
328
 
329
+ gr.Markdown("---\n**Veda Programming Assistant** - Learning from every conversation!")
 
 
 
330
 
331
 
 
332
  if __name__ == "__main__":
333
  demo.launch(server_name="0.0.0.0", server_port=7860)