from fastapi import FastAPI, HTTPException, Form from fastapi.responses import HTMLResponse 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(category: str = Form(...), value: int = Form(...)): # You can append the received category and value to a list if needed # categories.append(category) # values.append(value) # 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) @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)