File size: 904 Bytes
7161ebe 9179cf3 3dfd27d dc8a913 3dfd27d dc8a913 3dfd27d dc8a913 9179cf3 7161ebe ede4b3b 7161ebe ede4b3b 7161ebe |
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 |
from fastapi import FastAPI
from pydantic import BaseModel
import gradio as gr
import uvicorn
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# Erlaubt alle Ursprünge
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)
@app.get("/")
def read_root():
return gr_interface.launch(share=True)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
|