Spaces:
Runtime error
Runtime error
File size: 1,023 Bytes
4cb5616 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import gradio as gr
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
class Data():
__init__(self, data):
self.data = [[data]]
update(self):
self.data.append([new_data])
get_data():
return self.data
app = FastAPI()
data_for_app = new Data("initial data")
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Create a simple Gradio interface
def greet(name):
return f"Hello, {name}!"
gr.Blocks() as blocks:
gr.Dataframe(value=get_data, label="My Data")
# Mount Gradio app to root
app = gr.mount_gradio_app(app, interface, path="/")
# Custom POST endpoint
i = 0
@app.post("/endpoint")
async def custom_endpoint(data: dict):
i = i + 1
data_for_app.update(f"New data - item: {i}");
return {"message": "Received data", "data": data}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860) |