sreejang commited on
Commit
1db0cf9
Β·
verified Β·
1 Parent(s): 3ab7124

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,7 +1,7 @@
1
- """
2
- Smart Excel Analyst - Hugging Face Space
3
- Nepali + English Excel Analytics with AI Chat
4
- """
5
 
6
  import gradio as gr
7
  import pandas as pd
@@ -205,8 +205,8 @@ def chat(msg, hist):
205
  if not msg or not msg.strip():
206
  return "", hist
207
 
 
208
  if current_df is None:
209
- # βœ… FIXED: Use dict format for messages
210
  hist.append({"role": "user", "content": msg})
211
  hist.append({"role": "assistant", "content": "❌ Please upload an Excel file first!"})
212
  return "", hist
@@ -262,8 +262,8 @@ Answer based ONLY on the data above."""
262
  )
263
 
264
  reply = response.choices[0].message.content.strip()
265
-
266
- # βœ… FIXED: Use dict format with role and content
267
  hist.append({"role": "user", "content": msg})
268
  hist.append({"role": "assistant", "content": f"πŸ€– {reply}"})
269
  return "", hist
@@ -275,12 +275,13 @@ Answer based ONLY on the data above."""
275
 
276
 
277
  # ==========================================
278
- # GRADIO UI
279
  # ==========================================
280
  css = """
281
  .gradio-container {font-family: 'Segoe UI', sans-serif;}
282
  """
283
 
 
284
  with gr.Blocks(title="Smart Excel Analyst") as demo:
285
 
286
  gr.Markdown("""
@@ -329,8 +330,8 @@ with gr.Blocks(title="Smart Excel Analyst") as demo:
329
  - `Who has the highest loan amount?`
330
  """)
331
 
332
- # βœ… FIXED: Added type="messages" for new Gradio format
333
- chatbot = gr.Chatbot(height=450, type="messages")
334
 
335
  with gr.Row():
336
  with gr.Column(scale=4):
@@ -356,8 +357,11 @@ with gr.Blocks(title="Smart Excel Analyst") as demo:
356
  send_btn.click(chat, inputs=[msg_input, chatbot], outputs=[msg_input, chatbot])
357
  msg_input.submit(chat, inputs=[msg_input, chatbot], outputs=[msg_input, chatbot])
358
 
359
- # βœ… FIXED: Use server_name and server_port for HuggingFace
360
  demo.launch(
361
  server_name="0.0.0.0",
362
- server_port=7860
 
 
 
363
  )
 
1
+ # ==========================================
2
+ # Smart Excel Analyst - Hugging Face Space
3
+ # Nepali + English Excel Analytics with AI Chat
4
+ # ==========================================
5
 
6
  import gradio as gr
7
  import pandas as pd
 
205
  if not msg or not msg.strip():
206
  return "", hist
207
 
208
+ # βœ… Gradio 6.x: dict format with role/content
209
  if current_df is None:
 
210
  hist.append({"role": "user", "content": msg})
211
  hist.append({"role": "assistant", "content": "❌ Please upload an Excel file first!"})
212
  return "", hist
 
262
  )
263
 
264
  reply = response.choices[0].message.content.strip()
265
+
266
+ # βœ… Gradio 6.x dict message format
267
  hist.append({"role": "user", "content": msg})
268
  hist.append({"role": "assistant", "content": f"πŸ€– {reply}"})
269
  return "", hist
 
275
 
276
 
277
  # ==========================================
278
+ # GRADIO 6.x UI
279
  # ==========================================
280
  css = """
281
  .gradio-container {font-family: 'Segoe UI', sans-serif;}
282
  """
283
 
284
+ # βœ… Gradio 6.x: title only in gr.Blocks(), theme/css go in launch()
285
  with gr.Blocks(title="Smart Excel Analyst") as demo:
286
 
287
  gr.Markdown("""
 
330
  - `Who has the highest loan amount?`
331
  """)
332
 
333
+ # βœ… Gradio 6.x: NO type argument - uses dict format by default
334
+ chatbot = gr.Chatbot(height=450)
335
 
336
  with gr.Row():
337
  with gr.Column(scale=4):
 
357
  send_btn.click(chat, inputs=[msg_input, chatbot], outputs=[msg_input, chatbot])
358
  msg_input.submit(chat, inputs=[msg_input, chatbot], outputs=[msg_input, chatbot])
359
 
360
+ # βœ… Gradio 6.x: theme and css go in launch(), server_name for HF Spaces
361
  demo.launch(
362
  server_name="0.0.0.0",
363
+ server_port=7860,
364
+ theme=gr.themes.Soft(),
365
+ css=css,
366
+ ssr_mode=False
367
  )