import gradio as gr import google.generativeai as genai import os import json import re # 配置 API api_key = os.getenv("MY_API_KEY") genai.configure(api_key=api_key) # --- 定义 CSS 样式 --- custom_css = """ body { background-color: #0b0f14; } .report-container { background: #111827; border: 1px solid #1f2937; border-radius: 12px; padding: 20px; color: #e5e7eb; font-family: 'Inter', sans-serif; } .header-row { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #374151; padding-bottom: 15px; margin-bottom: 20px; } .score-circle { background: radial-gradient(circle, #3b82f6, #1d4ed8); width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; color: white; box-shadow: 0 0 15px rgba(59, 130, 246, 0.5); } .section-title { color: #60a5fa; font-size: 16px; font-weight: bold; margin: 15px 0 10px 0; display: flex; align-items: center; gap: 8px; } .card { background: #1f2937; border-radius: 8px; padding: 12px; margin-bottom: 10px; border-left: 4px solid #3b82f6; } .tag-container { display: flex; gap: 8px; margin-top: 10px; } .tag { background: #374151; padding: 4px 10px; border-radius: 4px; font-size: 12px; color: #9ca3af; border: 1px solid #4b5563; } .suggestion { background: #064e3b; border-left: 4px solid #10b981; padding: 10px; border-radius: 6px; margin-top: 8px; font-size: 14px; } """ def parse_and_format(ai_response): """提取 JSON 并渲染 HTML""" try: # 尝试从回复中找到 JSON 部分 json_str = re.search(r'\{.*\}', ai_response, re.DOTALL).group() data = json.loads(json_str) html = f"""
{data.get('technical', '')}