File size: 1,317 Bytes
0fae3be |
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 |
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()
|