mgokg commited on
Commit
1a1b3a8
·
verified ·
1 Parent(s): 4e4e893

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -3,10 +3,11 @@ from pydantic import BaseModel
3
  import gradio as gr
4
  import uvicorn
5
  from fastapi.middleware.cors import CORSMiddleware
 
6
 
7
  app = FastAPI()
8
 
9
- # Allow all origins
10
  app.add_middleware(
11
  CORSMiddleware,
12
  allow_origins=["*"],
@@ -26,7 +27,7 @@ async def create_item(item: Item):
26
  zeitstempel = item.zeitstempel
27
  return {"prompt": prompt, "zeitstempel": zeitstempel}
28
 
29
- # Initial prompt value
30
  prompt = ""
31
 
32
  def get_prompt():
@@ -34,12 +35,14 @@ def get_prompt():
34
 
35
  gr_interface = gr.Interface(fn=get_prompt, inputs=[], outputs="text", live=True)
36
 
37
- # Mount the Gradio app under "/gradio"
38
- app.mount("/gradio", gr_interface.app)
39
 
40
  @app.get("/")
41
  def read_root():
42
- return {"message": "Welcome to the root endpoint."}
43
 
44
  if __name__ == "__main__":
45
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
 
3
  import gradio as gr
4
  import uvicorn
5
  from fastapi.middleware.cors import CORSMiddleware
6
+ import threading
7
 
8
  app = FastAPI()
9
 
10
+ # Erlaube alle Ursprünge
11
  app.add_middleware(
12
  CORSMiddleware,
13
  allow_origins=["*"],
 
27
  zeitstempel = item.zeitstempel
28
  return {"prompt": prompt, "zeitstempel": zeitstempel}
29
 
30
+ # Initialer Wert für prompt
31
  prompt = ""
32
 
33
  def get_prompt():
 
35
 
36
  gr_interface = gr.Interface(fn=get_prompt, inputs=[], outputs="text", live=True)
37
 
38
+ def start_gradio():
39
+ gr_interface.launch()
40
 
41
  @app.get("/")
42
  def read_root():
43
+ return {"message": "Willkommen am Root-Endpunkt."}
44
 
45
  if __name__ == "__main__":
46
+ # Starte Gradio in einem separaten Thread
47
+ threading.Thread(target=start_gradio).start()
48
+ uvicorn.run(app, host="0.0.0.0", port=8000)