Spaces:
Sleeping
Sleeping
AdityaAdaki
commited on
Commit
·
ae71f1a
1
Parent(s):
d10ad3f
l5
Browse files
app.py
CHANGED
@@ -239,7 +239,7 @@ def get_ai_insights(market_data, state, district, market=None, commodity=None, l
|
|
239 |
}
|
240 |
|
241 |
response = requests.post(
|
242 |
-
f"{api_url}?key={
|
243 |
headers=headers,
|
244 |
json=payload,
|
245 |
timeout=20
|
@@ -470,8 +470,15 @@ app.logger.addHandler(handler)
|
|
470 |
def index():
|
471 |
try:
|
472 |
app.logger.info("Fetching initial market data")
|
|
|
|
|
|
|
|
|
|
|
473 |
initial_data = fetch_market_data()
|
|
|
474 |
states = sorted(initial_data['state'].dropna().unique()) if not initial_data.empty else []
|
|
|
475 |
except Exception as e:
|
476 |
app.logger.error(f"Error fetching initial data: {str(e)}")
|
477 |
states = []
|
@@ -484,7 +491,7 @@ def index():
|
|
484 |
except Exception as e:
|
485 |
app.logger.error(f"Template rendering error: {str(e)}")
|
486 |
return f"Error loading application: {str(e)}", 500
|
487 |
-
|
488 |
@app.route('/filter_data', methods=['POST'])
|
489 |
def filter_data():
|
490 |
app.logger.info("Received filter_data request")
|
@@ -505,11 +512,8 @@ def filter_data():
|
|
505 |
'plots': plots,
|
506 |
'insights': insights,
|
507 |
'success': not df.empty,
|
508 |
-
'hasStateDistrict': bool(state and district)
|
509 |
-
|
510 |
-
'cheapest_html': cheapest_table_html,
|
511 |
-
'costliest_html': costliest_table_html,
|
512 |
-
'market_stats': market_stats
|
513 |
}
|
514 |
|
515 |
return jsonify(response)
|
|
|
239 |
}
|
240 |
|
241 |
response = requests.post(
|
242 |
+
f"{api_url}?key={GEMINI_API}",
|
243 |
headers=headers,
|
244 |
json=payload,
|
245 |
timeout=20
|
|
|
470 |
def index():
|
471 |
try:
|
472 |
app.logger.info("Fetching initial market data")
|
473 |
+
# Check if CSV file exists
|
474 |
+
csv_path = "final_price_data.csv"
|
475 |
+
if not os.path.exists(csv_path):
|
476 |
+
app.logger.error(f"CSV file not found at: {os.path.abspath(csv_path)}")
|
477 |
+
|
478 |
initial_data = fetch_market_data()
|
479 |
+
app.logger.info(f"Initial data shape: {initial_data.shape if not initial_data.empty else 'Empty'}")
|
480 |
states = sorted(initial_data['state'].dropna().unique()) if not initial_data.empty else []
|
481 |
+
app.logger.info(f"Found {len(states)} states")
|
482 |
except Exception as e:
|
483 |
app.logger.error(f"Error fetching initial data: {str(e)}")
|
484 |
states = []
|
|
|
491 |
except Exception as e:
|
492 |
app.logger.error(f"Template rendering error: {str(e)}")
|
493 |
return f"Error loading application: {str(e)}", 500
|
494 |
+
|
495 |
@app.route('/filter_data', methods=['POST'])
|
496 |
def filter_data():
|
497 |
app.logger.info("Received filter_data request")
|
|
|
512 |
'plots': plots,
|
513 |
'insights': insights,
|
514 |
'success': not df.empty,
|
515 |
+
'hasStateDistrict': bool(state and district)
|
516 |
+
# Removed undefined variables
|
|
|
|
|
|
|
517 |
}
|
518 |
|
519 |
return jsonify(response)
|