fastapi / app.py
mgokg's picture
Update app.py
dc8a913 verified
raw
history blame
1.12 kB
from fastapi import FastAPI
from pydantic import BaseModel
import gradio as gr
import uvicorn
from fastapi.middleware.cors import CORSMiddleware
# Liste der Ursprünge, die Zugriff auf die Ressourcen haben sollen
origins = [ "http://localhost",
"http://localhost:8000",
"https://huggingface.co/mgokg",
# Füge hier weitere Ursprünge hinzu
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app = FastAPI()
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)
@app.get("/")
def read_root():
return gr_interface.launch(share=True)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)