Spaces:
Sleeping
Sleeping
kandi1clickkits
commited on
Commit
·
748cd0a
1
Parent(s):
da0318e
chart code with DB
Browse files
main.py
CHANGED
|
@@ -5,14 +5,15 @@ import gradio as gr
|
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
def create_chart(categories, values):
|
| 8 |
-
data = {"
|
| 9 |
-
plot = gr.LinePlot(data, every=5, x="
|
| 10 |
-
return plot
|
| 11 |
|
| 12 |
@app.post("/form/")
|
| 13 |
async def show_chart(categories: list, values: list):
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
@app.get("/visualization/", response_class=HTMLResponse)
|
| 18 |
async def show_visualization():
|
|
@@ -21,5 +22,6 @@ async def show_visualization():
|
|
| 21 |
categories = ["Category1", "Category2", "Category3"]
|
| 22 |
values = [10, 20, 30]
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
def create_chart(categories, values):
|
| 8 |
+
data = {"Date": categories, "Sales": values}
|
| 9 |
+
plot = gr.LinePlot(data, every=5, x="Date", y="Sales", y_title="Sales ($ millions)", overlay_point=True, width=500, height=500)
|
| 10 |
+
return plot.render()
|
| 11 |
|
| 12 |
@app.post("/form/")
|
| 13 |
async def show_chart(categories: list, values: list):
|
| 14 |
+
chart_html = create_chart(categories, values)
|
| 15 |
+
iframe_code = f'<iframe srcdoc="{chart_html}" width="600" height="400" frameborder="0"></iframe>'
|
| 16 |
+
return HTMLResponse(content=iframe_code, status_code=200)
|
| 17 |
|
| 18 |
@app.get("/visualization/", response_class=HTMLResponse)
|
| 19 |
async def show_visualization():
|
|
|
|
| 22 |
categories = ["Category1", "Category2", "Category3"]
|
| 23 |
values = [10, 20, 30]
|
| 24 |
|
| 25 |
+
chart_html = create_chart(categories, values)
|
| 26 |
+
iframe_code = f'<iframe srcdoc="{chart_html}" width="600" height="400" frameborder="0"></iframe>'
|
| 27 |
+
return HTMLResponse(content=iframe_code, status_code=200)
|