mlAPI / main.py
kandi1clickkits
chart code with DB
da0318e
raw
history blame
971 Bytes
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
import gradio as gr
app = FastAPI()
def create_chart(categories, values):
data = {"students": categories, "marks": values}
plot = gr.LinePlot(data, every=5, x="students", y="marks", y_title="marks (percent)", overlay_point=True, width=500, height=500)
return plot
@app.post("/form/")
async def show_chart(categories: list, values: list):
chart = create_chart(categories, values)
return HTMLResponse(content=chart.launch(), status_code=200)
@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]
chart = create_chart(categories, values)
return HTMLResponse(content=chart.launch(), status_code=200)