SurveyChatbot / app.py
aimanathar's picture
Update app.py
d50f7e6 verified
import gradio as gr
import pandas as pd
import os
# Load survey dataset from CSV
survey_data = None
try:
if os.path.exists("survey.csv"):
survey_data = pd.read_csv("survey.csv")
else:
# fallback fake dataset
survey_data = pd.DataFrame({
"employee": ["Aiman", "Ali", "Sara"],
"mood": ["Positive", "Negative", "Neutral"],
"recommendation": [
"Keep up the good work!",
"Take a short break to reduce stress.",
"Encourage more collaboration."
]
})
except Exception as e:
print("Error loading CSV:", str(e))
def chatbot(query):
try:
if not query or query.strip() == "":
return "⚠️ Please type a valid question."
query_lower = query.lower()
# Match employee name
for i, row in survey_data.iterrows():
if row["employee"].lower() in query_lower:
return f"✅ {row['employee']} is feeling **{row['mood']}**.\n💡 Recommendation: {row['recommendation']}"
# No match found
return "ℹ️ I don’t have data for that person. Try asking about Aiman, Ali, or Sara."
except Exception as e:
return f"🚨 Error: {str(e)}"
# Gradio Chat Interface
iface = gr.ChatInterface(fn=chatbot, title="Pulse Survey Chatbot")
iface.launch()