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")