File size: 860 Bytes
fb3a173
035d91e
fb3a173
035d91e
8557221
ad90944
 
a02591a
 
007a3ba
 
 
035d91e
fb3a173
 
 
a02591a
 
035d91e
 
 
a02591a
 
 
 
 
 
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
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from typing import List
import gradio as gr

app = FastAPI()

def create_gr_chart(categories, values):
    data = {"x": categories, "y": values}
    chart = gr.LineChart(data=data)
    return chart.launch()

@app.post("/form/")
async def show_chart(data: List[dict]):
    categories = [item["category"] for item in data]
    values = [item["value"] for item in data]

    return create_gr_chart(categories, values)

@app.get("/visualization/", response_class=HTMLResponse)
async def show_visualization():
    # For simplicity, I'm assuming you have two lists of categories and values
    # Modify this part based on your actual data structure
    categories = ["Category1", "Category2", "Category3"]
    values = [10, 20, 30]

    return create_gr_chart(categories, values)