Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, HTTPException | |
| from fastapi.responses import HTMLResponse | |
| import gradio as gr | |
| app = FastAPI() | |
| def create_chart(categories, values): | |
| data = {"Date": categories, "Sales": values} | |
| plot = gr.LinePlot(data, every=5, x="Date", y="Sales", y_title="Sales ($ millions)", overlay_point=True, width=500, height=500) | |
| return plot.render() | |
| async def show_chart(categories: list, values: list): | |
| chart_html = create_chart(categories, values) | |
| iframe_code = f'<iframe srcdoc="{chart_html}" width="600" height="400" frameborder="0"></iframe>' | |
| return HTMLResponse(content=iframe_code, status_code=200) | |
| 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] | |
| chart_html = create_chart(categories, values) | |
| iframe_code = f'<iframe srcdoc="{chart_html}" width="600" height="400" frameborder="0"></iframe>' | |
| return HTMLResponse(content=iframe_code, status_code=200) | |