aimanathar commited on
Commit
d50f7e6
·
verified ·
1 Parent(s): 80868f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -1,22 +1,25 @@
1
  import gradio as gr
2
- import json
3
  import os
4
 
5
- # Load fake survey dataset safely
6
- survey_data = []
7
  try:
8
- if os.path.exists("survey.json"):
9
- with open("survey.json", "r") as f:
10
- survey_data = json.load(f)
11
  else:
12
- survey_data = [
13
- {"employee": "Aiman", "mood": "Positive", "recommendation": "Keep up the good work!"},
14
- {"employee": "Ali", "mood": "Negative", "recommendation": "Take a short break to reduce stress."},
15
- {"employee": "Sara", "mood": "Neutral", "recommendation": "Encourage more collaboration."}
16
- ]
 
 
 
 
 
17
  except Exception as e:
18
- survey_data = []
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
- # Check each employee in dataset
30
- for entry in survey_data:
31
- if entry["employee"].lower() in query_lower:
32
- return f"✅ {entry['employee']} is feeling **{entry['mood']}**.\n💡 Recommendation: {entry['recommendation']}"
33
 
34
- # If employee not found
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"🚨 Internal Error: {str(e)}"
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