Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,28 @@
|
|
| 1 |
import os
|
| 2 |
import uvicorn
|
| 3 |
from fastapi import FastAPI
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
return {"message": "pong"}
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
msg = gr.Textbox()
|
| 15 |
-
out = gr.Textbox()
|
| 16 |
-
msg.change(lambda x: f"You typed: {x}", msg, out)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
|
|
|
|
| 1 |
import os
|
| 2 |
import uvicorn
|
| 3 |
from fastapi import FastAPI
|
| 4 |
+
from fastapi.middleware.wsgi import WSGIMiddleware
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
# import your separate logic
|
| 8 |
+
from api import api_app # FastAPI app for API endpoints
|
| 9 |
+
from main import build_ui # function that returns a Gradio Blocks/Interface
|
| 10 |
|
| 11 |
+
# Create main FastAPI app
|
| 12 |
+
app = FastAPI()
|
|
|
|
| 13 |
|
| 14 |
+
# Mount API under /api
|
| 15 |
+
app.mount("/api", api_app)
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Build and mount Gradio UI under /
|
| 18 |
+
gradio_app = gr.routes.App(build_ui()) # build_ui() returns gr.Blocks/Interface
|
| 19 |
+
app.mount("/", gradio_app)
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
| 22 |
+
# Use Hugging Face's assigned port, fallback to 7860 locally
|
| 23 |
+
port = int(os.environ.get("PORT", 7860))
|
| 24 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|
| 25 |
+
|
| 26 |
|
| 27 |
|
| 28 |
|