Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,26 @@
|
|
| 1 |
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
import uvicorn
|
| 4 |
from fastapi import FastAPI
|
|
|
|
| 5 |
|
| 6 |
-
# --- FastAPI app ---
|
| 7 |
api = FastAPI()
|
| 8 |
|
| 9 |
@api.get("/ping")
|
| 10 |
async def ping():
|
| 11 |
return {"message": "pong"}
|
| 12 |
|
| 13 |
-
# --- Gradio app ---
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
-
gr.Markdown("#
|
| 16 |
-
|
| 17 |
-
out = gr.Textbox(
|
| 18 |
-
|
| 19 |
|
| 20 |
-
# Mount
|
| 21 |
api = gr.mount_gradio_app(api, demo, path="/")
|
| 22 |
|
| 23 |
if __name__ == "__main__":
|
| 24 |
-
port = int(os.environ.get("PORT", 7860)) # HF Spaces
|
| 25 |
uvicorn.run(api, host="0.0.0.0", port=port)
|
| 26 |
|
| 27 |
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import uvicorn
|
| 3 |
from fastapi import FastAPI
|
| 4 |
+
import gradio as gr
|
| 5 |
|
|
|
|
| 6 |
api = FastAPI()
|
| 7 |
|
| 8 |
@api.get("/ping")
|
| 9 |
async def ping():
|
| 10 |
return {"message": "pong"}
|
| 11 |
|
|
|
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
+
gr.Markdown("## Gradio + FastAPI running in HF Spaces")
|
| 14 |
+
msg = gr.Textbox()
|
| 15 |
+
out = gr.Textbox()
|
| 16 |
+
msg.change(lambda x: f"You typed: {x}", msg, out)
|
| 17 |
|
| 18 |
+
# Mount gradio at root
|
| 19 |
api = gr.mount_gradio_app(api, demo, path="/")
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
| 22 |
+
port = int(os.environ.get("PORT", 7860)) # 👈 use HF Spaces port
|
| 23 |
uvicorn.run(api, host="0.0.0.0", port=port)
|
| 24 |
|
| 25 |
|
| 26 |
+
|