Spaces:
Runtime error
Runtime error
Initial WorkWise backend deployment FastAPI app hello world
Browse files- app copy 2.py +26 -0
- app.py +9 -19
app copy 2.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
app.py
CHANGED
|
@@ -1,26 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from fastapi import FastAPI
|
| 3 |
import spaces
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
@spaces.GPU
|
| 8 |
-
def
|
| 9 |
-
# Your GPU
|
| 10 |
return result
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 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 |
-
|
| 26 |
-
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import spaces
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
import uvicorn
|
| 5 |
+
from threading import Thread
|
| 6 |
|
| 7 |
@spaces.GPU
|
| 8 |
+
def process(data):
|
| 9 |
+
# Your GPU logic
|
| 10 |
return result
|
| 11 |
|
| 12 |
+
# Minimal Gradio UI
|
| 13 |
+
demo = gr.Interface(fn=process, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Launch Gradio (keeps space alive)
|
| 16 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|