Spaces:
Sleeping
Sleeping
File size: 2,331 Bytes
b2315b1 |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import google.generativeai as genai
import json
# Load data from context.txt file
def load_context_data():
try:
with open('context.txt', 'r') as file:
return json.load(file)
except FileNotFoundError:
print("Error: context.txt file not found")
return None
except json.JSONDecodeError:
print("Error: Invalid JSON format in context.txt")
return None
# Load the context data from file
context = load_context_data()
if not context:
print("Failed to load context data. Please check your context.txt file.")
exit(1)
genai.configure(api_key="AIzaSyBWACJwKQVwEwACVcoVANgYOXXinwuPNFw") # Get free: https://aistudio.google.com/app/apikey
# THE ONLY PROMPT β 100% AGENT POWER
AGENT_PROMPT = f"""
Deatail Report On Topic
Your mission: Generate a **complete, 9-page, print-perfect HTML report** using **ONLY** the data below.
RULES:
- Use ONLY HTML + CSS
- No JavaScript (except 1 line for footer)
- A4 pages, 20mm padding
- Fonts: Times New Roman body, Arial headings
- Print-perfect: @media print {{ -webkit-print-color-adjust: exact; }}
- Use CSS variables, counters, SVG, conic-gradient
- Every chart MUST have: X-axis label, Y-axis label, grid, values
YOUR DATA:
{json.dumps(context, indent=2)}
TASK:
1. Read ALL 10 conversations
2. Extract every number, label, trend
3. Decide which charts to create (bar, line, scatter, pie, table)
4. Auto-label axes with real field names
5. Write insights in plain English
6. Add NEW charts if you discover patterns (e.g., "Stroke vs BMI + Age")
7. Title: "STROKE RISK INSIGHTS β AI-GENERATED REPORT"
8. Date: November 03, 2025
9. 9 pages: Cover β TOC β Summary β Charts β Insights β Recommendations β Appendix
OUTPUT:
- ONLY the full HTML
- Inside ```html
- No explanations
"""
# RUN THE AGENT
model = genai.GenerativeModel("gemini-2.5-pro")
response = model.generate_content(AGENT_PROMPT)
# CLEAN & SAVE
html = response.text
if "```html" in html:
html = html.split("```html", 1)[1].rsplit("```", 1)[0].strip()
with open("AI_GENERATED_STROKE_REPORT.html", "w", encoding="utf-8") as f:
f.write(html)
print("AI AGENT REPORT GENERATED!")
print("File: AI_GENERATED_STROKE_REPORT.html")
print("Open β Ctrl+P β Save as PDF") |