Spaces:
Runtime error
Runtime error
Initial WorkWise backend merged main.py -> app.py
Browse files- app.py +14 -12
- app.py.min.working +2 -1
app.py
CHANGED
|
@@ -1,24 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI
|
|
|
|
| 3 |
|
| 4 |
-
# Minimal FastAPI
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
-
@
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
@app.get("/test")
|
| 12 |
-
async def test():
|
| 13 |
return {"message": "FastAPI is working"}
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
# Mount
|
| 22 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
|
|
|
| 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 {"message": "FastAPI is working"}
|
| 11 |
+
#return result
|
| 12 |
|
| 13 |
+
# FastAPI endpoint
|
| 14 |
+
@app.get("/api/predict")
|
| 15 |
+
async def predict(input: str):
|
| 16 |
+
result = your_gpu_function(input)
|
| 17 |
+
return {"result": result}
|
| 18 |
|
| 19 |
+
# Gradio interface (required for ZeroGPU)
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Interface(fn=your_gpu_function, inputs="text", outputs="text")
|
| 22 |
|
| 23 |
+
# Mount FastAPI to Gradio
|
| 24 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
app.py.min.working
CHANGED
|
@@ -7,7 +7,8 @@ app = FastAPI()
|
|
| 7 |
@spaces.GPU
|
| 8 |
def your_gpu_function(input_data):
|
| 9 |
# Your GPU computation
|
| 10 |
-
return
|
|
|
|
| 11 |
|
| 12 |
# FastAPI endpoint
|
| 13 |
@app.get("/api/predict")
|
|
|
|
| 7 |
@spaces.GPU
|
| 8 |
def your_gpu_function(input_data):
|
| 9 |
# Your GPU computation
|
| 10 |
+
return {"message": "FastAPI is working"}
|
| 11 |
+
#return result
|
| 12 |
|
| 13 |
# FastAPI endpoint
|
| 14 |
@app.get("/api/predict")
|