Spaces:
Runtime error
Runtime error
Initial WorkWise backend deployment FastAPI app hello world
Browse files- app copy.py +34 -0
- app.py +18 -26
app copy.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
WorkWise Backend - Hugging Face ZeroGPU Entry Point
|
| 3 |
+
This file exposes the top-level `app` variable for Hugging Face Spaces.
|
| 4 |
+
"""
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from fastapi import FastAPI
|
| 7 |
+
from app.main import app as fastapi_app # your existing FastAPI app
|
| 8 |
+
|
| 9 |
+
# Mount FastAPI under Gradio
|
| 10 |
+
#gradio_app = gr.Blocks()
|
| 11 |
+
#gradio_app.launch = lambda *args, **kwargs: None # Dummy launch; not used
|
| 12 |
+
|
| 13 |
+
# --- Small Gradio heartbeat UI at "/" ---
|
| 14 |
+
with gr.Blocks(title="WorkWise Backend") as landing:
|
| 15 |
+
gr.Markdown("# ✅ WorkWise backend is running on Hugging Face ZeroGPU")
|
| 16 |
+
gr.Markdown("Visit **/docs** for Swagger or **/api** for the REST API.")
|
| 17 |
+
gr.Button("Open API docs").click(
|
| 18 |
+
None,
|
| 19 |
+
js="() => window.open('/docs', '_self')"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Hugging Face expects a variable called `app`
|
| 23 |
+
root = FastAPI(title="WorkWise Backend on ZeroGPU")
|
| 24 |
+
|
| 25 |
+
# Mount your existing FastAPI app !!
|
| 26 |
+
root.mount("/api", fastapi_app)
|
| 27 |
+
|
| 28 |
+
#@app.get("/")
|
| 29 |
+
#def root():
|
| 30 |
+
# return {"message": "WorkWise Backend (Faiss + FastAPI) on ZeroGPU"}
|
| 31 |
+
|
| 32 |
+
# Mount Gradio landing page at "/"
|
| 33 |
+
# NOTE: mount_gradio_app returns a FastAPI ASGI app — keep it in a variable named `app`
|
| 34 |
+
app = gr.mount_gradio_app(root, landing, path="/")
|
app.py
CHANGED
|
@@ -1,34 +1,26 @@
|
|
| 1 |
-
"""
|
| 2 |
-
WorkWise Backend - Hugging Face ZeroGPU Entry Point
|
| 3 |
-
This file exposes the top-level `app` variable for Hugging Face Spaces.
|
| 4 |
-
"""
|
| 5 |
import gradio as gr
|
| 6 |
from fastapi import FastAPI
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
#gradio_app = gr.Blocks()
|
| 11 |
-
#gradio_app.launch = lambda *args, **kwargs: None # Dummy launch; not used
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
gr.Button("Open API docs").click(
|
| 18 |
-
None,
|
| 19 |
-
js="() => window.open('/docs', '_self')"
|
| 20 |
-
)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
# return {"message": "WorkWise Backend (Faiss + FastAPI) on ZeroGPU"}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
app = gr.mount_gradio_app(root, landing, path="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI
|
| 3 |
+
import spaces
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
@spaces.GPU
|
| 8 |
+
def your_gpu_function(input_data):
|
| 9 |
+
# Your GPU computation
|
| 10 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# FastAPI endpoint
|
| 13 |
+
@app.get("/api/predict")
|
| 14 |
+
async def predict(input: str):
|
| 15 |
+
result = your_gpu_function(input)
|
| 16 |
+
return {"result": result}
|
| 17 |
|
| 18 |
+
# Gradio interface (required for ZeroGPU)
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
gr.Interface(fn=your_gpu_function, inputs="text", outputs="text")
|
| 21 |
|
| 22 |
+
# Mount FastAPI to Gradio
|
| 23 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
|
|
|
| 24 |
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|
|
|