|
import gradio as gr |
|
import httpx |
|
import asyncio |
|
|
|
async def async_request(url, params): |
|
async with httpx.AsyncClient() as client: |
|
response = await client.get(url, params=params) |
|
return response.json() |
|
|
|
async def fetch_data(endpoint, param): |
|
url = f"https://api.example.com/{endpoint}" |
|
response = await async_request(url, {"param": param}) |
|
return response |
|
|
|
def create_ui(): |
|
with gr.Blocks() as demo: |
|
with gr.Tabs(): |
|
with gr.TabItem("Home"): |
|
gr.Markdown("Welcome to EcoPropertyRetrofitGPT") |
|
|
|
with gr.TabItem("Data"): |
|
with gr.Accordion("Fetch Data", open=False): |
|
param = gr.Textbox(label="Parameter") |
|
output = gr.JSON(label="Response") |
|
|
|
def fetch_data_sync(param): |
|
return asyncio.run(fetch_data("data", param)) |
|
|
|
fetch_button = gr.Button("Fetch Data") |
|
fetch_button.click(fetch_data_sync, inputs=param, outputs=output) |
|
|
|
with gr.TabItem("Analysis"): |
|
with gr.Accordion("Run Analysis", open=False): |
|
param = gr.Textbox(label="Analysis Parameter") |
|
output = gr.JSON(label="Analysis Result") |
|
|
|
def run_analysis_sync(param): |
|
return asyncio.run(fetch_data("analysis", param)) |
|
|
|
run_button = gr.Button("Run Analysis") |
|
run_button.click(run_analysis_sync, inputs=param, outputs=output) |
|
|
|
demo.launch(server_name="0.0.0.0", server_port=8000, share=True) |
|
|
|
if __name__ == "__main__": |
|
create_ui() |
|
|