fastapi / app.py
mgokg's picture
Update app.py
4e4e893 verified
raw
history blame
979 Bytes
from fastapi import FastAPI
from pydantic import BaseModel
import gradio as gr
import uvicorn
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# Allow all origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class Item(BaseModel):
prompt: str
zeitstempel: int
@app.post("/items/")
async def create_item(item: Item):
global prompt
prompt = item.prompt
zeitstempel = item.zeitstempel
return {"prompt": prompt, "zeitstempel": zeitstempel}
# Initial prompt value
prompt = ""
def get_prompt():
return prompt
gr_interface = gr.Interface(fn=get_prompt, inputs=[], outputs="text", live=True)
# Mount the Gradio app under "/gradio"
app.mount("/gradio", gr_interface.app)
@app.get("/")
def read_root():
return {"message": "Welcome to the root endpoint."}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)