File size: 1,768 Bytes
794a200
ceb5307
 
794a200
ceb5307
 
 
 
 
 
 
 
 
794a200
 
ceb5307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
794a200
8e05fd0
f817edc
 
 
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
41
42
43
44
45
46
47
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=7860, share=True)

if __name__ == "__main__":
    create_ui()