Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
survey_data =
|
| 7 |
try:
|
| 8 |
-
if os.path.exists("survey.
|
| 9 |
-
|
| 10 |
-
survey_data = json.load(f)
|
| 11 |
else:
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
except Exception as e:
|
| 18 |
-
|
| 19 |
-
print("Error loading survey.json:", str(e))
|
| 20 |
|
| 21 |
|
| 22 |
def chatbot(query):
|
|
@@ -26,16 +29,16 @@ def chatbot(query):
|
|
| 26 |
|
| 27 |
query_lower = query.lower()
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
for
|
| 31 |
-
if
|
| 32 |
-
return f"✅ {
|
| 33 |
|
| 34 |
-
#
|
| 35 |
return "ℹ️ I don’t have data for that person. Try asking about Aiman, Ali, or Sara."
|
| 36 |
-
|
| 37 |
except Exception as e:
|
| 38 |
-
return f"🚨
|
| 39 |
|
| 40 |
|
| 41 |
# Gradio Chat Interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Load survey dataset from CSV
|
| 6 |
+
survey_data = None
|
| 7 |
try:
|
| 8 |
+
if os.path.exists("survey.csv"):
|
| 9 |
+
survey_data = pd.read_csv("survey.csv")
|
|
|
|
| 10 |
else:
|
| 11 |
+
# fallback fake dataset
|
| 12 |
+
survey_data = pd.DataFrame({
|
| 13 |
+
"employee": ["Aiman", "Ali", "Sara"],
|
| 14 |
+
"mood": ["Positive", "Negative", "Neutral"],
|
| 15 |
+
"recommendation": [
|
| 16 |
+
"Keep up the good work!",
|
| 17 |
+
"Take a short break to reduce stress.",
|
| 18 |
+
"Encourage more collaboration."
|
| 19 |
+
]
|
| 20 |
+
})
|
| 21 |
except Exception as e:
|
| 22 |
+
print("Error loading CSV:", str(e))
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def chatbot(query):
|
|
|
|
| 29 |
|
| 30 |
query_lower = query.lower()
|
| 31 |
|
| 32 |
+
# Match employee name
|
| 33 |
+
for i, row in survey_data.iterrows():
|
| 34 |
+
if row["employee"].lower() in query_lower:
|
| 35 |
+
return f"✅ {row['employee']} is feeling **{row['mood']}**.\n💡 Recommendation: {row['recommendation']}"
|
| 36 |
|
| 37 |
+
# No match found
|
| 38 |
return "ℹ️ I don’t have data for that person. Try asking about Aiman, Ali, or Sara."
|
| 39 |
+
|
| 40 |
except Exception as e:
|
| 41 |
+
return f"🚨 Error: {str(e)}"
|
| 42 |
|
| 43 |
|
| 44 |
# Gradio Chat Interface
|