1+ from flask import Flask , request , jsonify
2+ from ago import process_energy_file , handle_sustainability_goal , generate_response
3+ from vtracker import df # Assuming `vtracker.py` has loaded the DataFrame
4+
5+ app = Flask (__name__ )
6+
7+ @app .route ('/api/sustainability_goal' , methods = ['POST' ])
8+ def set_sustainability_goal ():
9+ data = request .json # Receive data from frontend
10+ choice = data .get ('choice' )
11+ response = handle_sustainability_goal ()
12+ return jsonify ({'message' : response })
13+
14+ @app .route ('/api/energy_bill' , methods = ['POST' ])
15+ def process_energy_bill ():
16+ file_content = request .json .get ('file_content' )
17+ file_path = 'temp_energy_bill.json' # Save content temporarily
18+ with open (file_path , 'w' ) as f :
19+ f .write (file_content )
20+ result = process_energy_file (file_path )
21+ return jsonify (result )
22+
23+ @app .route ('/api/recommendations' , methods = ['POST' ])
24+ def get_recommendations ():
25+ analysis = request .json .get ('analysis' )
26+ response = generate_response (f"Based on analysis: { analysis } \n Provide recommendations." )
27+ return jsonify ({'recommendations' : response })
28+
29+ @app .route ('/api/vtracker_data' , methods = ['GET' ])
30+ def get_vtracker_data ():
31+ # Convert DataFrame to JSON for visualization
32+ data = df .to_dict (orient = 'records' )
33+ return jsonify (data )
34+
35+ if __name__ == '__main__' :
36+ app .run (debug = True )
0 commit comments