| import gradio as gr | |
| import requests | |
| BASE_URL = "https://green-guard-cyber-ai-api.vercel.app" | |
| def fetch_latest(): | |
| res = requests.get(f"{BASE_URL}/insights/latest") | |
| return res.json() | |
| def fetch_by_index(index): | |
| res = requests.get(f"{BASE_URL}/insights/{int(index)}") | |
| return res.json() | |
| def fetch_top(limit): | |
| res = requests.get(f"{BASE_URL}/insights?limit={int(limit)}") | |
| return res.json() | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## πΏ GreenGuard ESG Intel Explorer") | |
| gr.Markdown("Built by Allsafeafrica β powered by Hugging Face + FastAPI") | |
| with gr.Tab("π Latest Insight"): | |
| btn_latest = gr.Button("Fetch Latest ESG Entry") | |
| out_latest = gr.JSON() | |
| btn_latest.click(fn=fetch_latest, outputs=out_latest) | |
| with gr.Tab("π Get by Index"): | |
| idx = gr.Number(label="Index", value=0) | |
| btn_idx = gr.Button("Fetch Entry") | |
| out_idx = gr.JSON() | |
| btn_idx.click(fn=fetch_by_index, inputs=idx, outputs=out_idx) | |
| with gr.Tab("π Top N Records"): | |
| slider = gr.Slider(minimum=1, maximum=50, step=1, label="How many entries?", value=10) | |
| btn_all = gr.Button("Fetch") | |
| out_all = gr.JSON() | |
| btn_all.click(fn=fetch_top, inputs=slider, outputs=out_all) | |
| demo.launch() | |