sagar004 commited on
Commit
32746e6
Β·
verified Β·
1 Parent(s): 7f8e2d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -50,6 +50,12 @@ def detect_anomaly(csv_file):
50
  return "βœ… No significant anomalies detected."
51
  return "⚠️ Anomalies found:\\n" + anomalies.to_string(index=False)
52
 
 
 
 
 
 
 
53
 
54
  # Gradio Interface
55
  app = gr.TabbedInterface(
@@ -58,9 +64,10 @@ app = gr.TabbedInterface(
58
  gr.Interface(fn=citizen_feedback, inputs=gr.Textbox(lines=2, label="Describe the Issue"), outputs="text", title="πŸ“£ Citizen Feedback"),
59
  gr.Interface(fn=kpi_forecasting, inputs=gr.File(label="Upload CSV with Year and Value columns"), outputs="text", title="πŸ“Š KPI Forecasting"),
60
  gr.Interface(fn=eco_tips, inputs=gr.Textbox(lines=2, label="Keyword (e.g. Plastic, Solar)"), outputs="text", title="🌱 Eco Tips Generator"),
61
- gr.Interface(fn=detect_anomaly, inputs=gr.File(label="Upload CSV with 'value' column"), outputs="text", title="🚨 Anomaly Detection")
 
62
  ],
63
- tab_names=["Summarize", "Feedback", "Forecast", "Eco Tips", "Anomalies"],
64
  title="πŸŒ† Sustainable Smart City Assistant"
65
  )
66
 
 
50
  return "βœ… No significant anomalies detected."
51
  return "⚠️ Anomalies found:\\n" + anomalies.to_string(index=False)
52
 
53
+ # module 6: chat assistant
54
+ def chat_assistant(question):
55
+ prompt = f"Answer this smart city sustainability question:\n\nQ: {question}\nA:"
56
+ result = llm(prompt, max_new_tokens=200, temperature=0.7)[0]["generated_text"]
57
+ return result.replace(prompt, "").strip()
58
+
59
 
60
  # Gradio Interface
61
  app = gr.TabbedInterface(
 
64
  gr.Interface(fn=citizen_feedback, inputs=gr.Textbox(lines=2, label="Describe the Issue"), outputs="text", title="πŸ“£ Citizen Feedback"),
65
  gr.Interface(fn=kpi_forecasting, inputs=gr.File(label="Upload CSV with Year and Value columns"), outputs="text", title="πŸ“Š KPI Forecasting"),
66
  gr.Interface(fn=eco_tips, inputs=gr.Textbox(lines=2, label="Keyword (e.g. Plastic, Solar)"), outputs="text", title="🌱 Eco Tips Generator"),
67
+ gr.Interface(fn=detect_anomaly, inputs=gr.File(label="Upload CSV with 'value' column"), outputs="text", title="🚨 Anomaly Detection"),
68
+ gr.Interface(fn=chat_assistant, inputs=gr.Textbox(lines=2, label="Ask your question"), outputs="text", title="πŸ’¬ Smart City Chat")
69
  ],
70
+ tab_names=["Summarize", "Feedback", "Forecast", "Eco Tips", "Anomalies", "Chat"],
71
  title="πŸŒ† Sustainable Smart City Assistant"
72
  )
73