-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (38 loc) · 1.47 KB
/
app.py
File metadata and controls
51 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask, render_template, request, jsonify
import google.generativeai as genai
import os
from dotenv import load_dotenv
load_dotenv()
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
app = Flask(__name__)
def get_system_prompt():
try:
with open('identity_check.txt', 'r') as f:
return f.read()
except FileNotFoundError:
return "You are a helpful AI assistant."
@app.route('/')
def index():
return render_template('index.html')
@app.route('/analyze', methods=['POST'])
def analyze_email():
data = request.json
email_content = data.get('email_text', '')
if not email_content:
return jsonify({"error": "No email content provided"}), 400
try:
# Connect to the AI Model
model = genai.GenerativeModel('gemini-pro')
# Combine user instructions with the user's email
system_instruction = get_system_prompt()
full_prompt = f"{system_instruction}\n\nEMAIL CONTENT:\n{email_content}"
# Send to Google
response = model.generate_content(full_prompt)
# Clean up the response (remove Markdown formatting if present)
cleaned_response = response.text.replace('```json', '').replace('```', '')
return cleaned_response, 200, {'Content-Type': 'application/json'}
except Exception as e:
return jsonify({"error": str(e)}), 500
# --- START THE SERVER ---
if __name__ == '__main__':
app.run(debug=True)