|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
import gradio as gr |
|
import uvicorn |
|
from fastapi.middleware.cors import CORSMiddleware |
|
import threading |
|
|
|
app = FastAPI() |
|
|
|
|
|
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} |
|
|
|
|
|
prompt = "" |
|
|
|
def get_prompt(prompt): |
|
return prompt |
|
|
|
|
|
def show_html(): |
|
return """ |
|
""" |
|
|
|
with gr.Blocks() as demo: |
|
gr.HTML(show_html) |
|
with gr.Row(): |
|
|
|
details_output = gr.Textbox(label="Ausgabe") |
|
with gr.Row(): |
|
ort_input = gr.Textbox(label="", placeholder="ask anything...") |
|
with gr.Row(): |
|
button = gr.Button("Senden") |
|
|
|
|
|
button.click(fn=get_prompt, inputs=ort_input, outputs=details_output) |
|
|
|
|
|
demo.launch() |
|
|
|
|
|
@app.get("/") |
|
def read_root(): |
|
return {"message": "Willkommen am Root-Endpunkt."} |
|
|
|
if __name__ == "__main__": |
|
|
|
threading.Thread(target=start_gradio).start() |
|
uvicorn.run(app, host="0.0.0.0", port=8000) |
|
|