File size: 1,180 Bytes
7161ebe
 
 
 
9179cf3
1a1b3a8
9179cf3
 
4e4e893
bde8d16
 
5a2a00b
f94c98f
bde8d16
4da036d
 
1a1b3a8
4e4e893
 
bfe2a30
4e4e893
 
3dfd27d
d87aa79
dc8a913
9179cf3
7161ebe
 
 
 
 
 
 
 
 
 
 
1a1b3a8
7161ebe
 
 
 
 
ede4b3b
7161ebe
1a1b3a8
 
4e4e893
ede4b3b
 
1a1b3a8
7161ebe
 
1a1b3a8
 
 
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
47
48
49
50
51
52
53
54
55
56
57
from fastapi import FastAPI
from pydantic import BaseModel
import gradio as gr
import uvicorn
from fastapi.middleware.cors import CORSMiddleware
import threading

app = FastAPI()

origins = [ 
    "http://localhost", 
    "http://localhost:8000",
    "https://try.w3schools.com",
] 


# Erlaube alle Ursprünge
app.add_middleware(
    CORSMiddleware,
    allow_origins=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}

# Initialer Wert für prompt
prompt = ""

def get_prompt():
    return prompt

gr_interface = gr.Interface(fn=get_prompt, inputs=[], outputs="text", live=True)

def start_gradio():
    gr_interface.launch()

@app.get("/")
def read_root():
    return {"message": "Willkommen am Root-Endpunkt."}

if __name__ == "__main__":
    # Starte Gradio in einem separaten Thread
    threading.Thread(target=start_gradio).start()
    uvicorn.run(app, host="0.0.0.0", port=8000)