tstone87 commited on
Commit
babe37e
·
verified ·
1 Parent(s): 1495a62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -11,9 +11,15 @@ DATA_FILE = "colorado_foodstamps.json"
11
  def load_json_data():
12
  try:
13
  with open(DATA_FILE, "r", encoding="utf-8") as f:
14
- return json.load(f)
15
- except FileNotFoundError:
16
- return {"error": "Data file not found! Please upload a valid JSON file."}
 
 
 
 
 
 
17
 
18
  data = load_json_data()
19
 
@@ -56,4 +62,4 @@ def chatbot_response(message, history):
56
  # 🔹 Gradio Chat Interface
57
  demo = gr.ChatInterface(chatbot_response, textbox=gr.Textbox(placeholder="Ask about Colorado food stamps..."))
58
 
59
- demo.launch()
 
11
  def load_json_data():
12
  try:
13
  with open(DATA_FILE, "r", encoding="utf-8") as f:
14
+ data = json.load(f)
15
+
16
+ # Ensure data is a dictionary, not a list
17
+ if isinstance(data, list):
18
+ raise ValueError("Expected a dictionary but found a list. Please update your JSON file format.")
19
+
20
+ return data
21
+ except (FileNotFoundError, ValueError) as e:
22
+ return {"error": f"Data loading issue: {e}"}
23
 
24
  data = load_json_data()
25
 
 
62
  # 🔹 Gradio Chat Interface
63
  demo = gr.ChatInterface(chatbot_response, textbox=gr.Textbox(placeholder="Ask about Colorado food stamps..."))
64
 
65
+ demo.launch()