0Learn commited on
Commit
7c3e7c7
·
verified ·
1 Parent(s): a545554

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,9 +1,9 @@
1
- import uvicorn
2
  from fastapi import FastAPI
3
  from fastapi.middleware.cors import CORSMiddleware
4
- from backend import app as backend_app
5
  from frontend import create_interface
6
- import threading
7
 
8
  # Create the main FastAPI app
9
  app = FastAPI()
@@ -18,7 +18,7 @@ app.add_middleware(
18
  )
19
 
20
  # Include the backend routes
21
- app.include_router(backend_app)
22
 
23
  # Create the Gradio interface
24
  iface = create_interface()
@@ -26,6 +26,9 @@ iface = create_interface()
26
  # Mount the Gradio app
27
  app = gr.mount_gradio_app(app, iface, path="/")
28
 
 
 
 
29
  if __name__ == "__main__":
30
- # Run the FastAPI server
31
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
+ import gradio as gr
2
  from fastapi import FastAPI
3
  from fastapi.middleware.cors import CORSMiddleware
4
+ from backend import router as backend_router
5
  from frontend import create_interface
6
+ import os
7
 
8
  # Create the main FastAPI app
9
  app = FastAPI()
 
18
  )
19
 
20
  # Include the backend routes
21
+ app.include_router(backend_router)
22
 
23
  # Create the Gradio interface
24
  iface = create_interface()
 
26
  # Mount the Gradio app
27
  app = gr.mount_gradio_app(app, iface, path="/")
28
 
29
+ # Hugging Face Spaces provides the port number in the PORT environment variable
30
+ port = int(os.environ.get("PORT", 7860))
31
+
32
  if __name__ == "__main__":
33
+ import uvicorn
34
+ uvicorn.run(app, host="0.0.0.0", port=port)