rairo commited on
Commit
a71d24c
·
verified ·
1 Parent(s): 17a7e15

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -0
main.py CHANGED
@@ -76,6 +76,25 @@ def process_receipt(model, image):
76
  except Exception as e:
77
  st.error(f"Gemini error: {str(e)}")
78
  return "{}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  # ========================================
80
  # Authentication Endpoints
81
  # ========================================
 
76
  except Exception as e:
77
  st.error(f"Gemini error: {str(e)}")
78
  return "{}"
79
+
80
+
81
+ # Write report
82
+ @app.route('/api/write-report', methods=['POST'])
83
+ def generate_report():
84
+ prompt = """You are the TrueSpend AI analyst, analyze this transaction data
85
+ and write an insightful business report on the spending habits of the users """
86
+ try:
87
+ # Get the transaction data from the request body
88
+ transaction_data = request.get_json()
89
+ transaction_json_string = json.dumps(transaction_data['transactions'])
90
+
91
+ # Assuming model is defined/imported elsewhere in your Flask app
92
+ response = model.generate_content([prompt, transaction_json_string])
93
+ report = response.text
94
+ return jsonify({"report": report}) # Wrap the report in an object
95
+
96
+ except Exception as e:
97
+ return jsonify({"error": str(e)}), 500
98
  # ========================================
99
  # Authentication Endpoints
100
  # ========================================