Spaces:
Running
on
Zero
Running
on
Zero
testing gpu with uvicorn
Browse files
app.py
CHANGED
|
@@ -1,10 +1,19 @@
|
|
| 1 |
import base64
|
| 2 |
import json
|
| 3 |
-
|
| 4 |
import gradio as gr
|
| 5 |
import spaces
|
| 6 |
import torch
|
| 7 |
from spaces.zero.client import _get_token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
@spaces.GPU(duration=4*60) # Not possible with IP-based quotas
|
| 10 |
def inner():
|
|
@@ -19,4 +28,16 @@ def greet(request: gr.Request, n):
|
|
| 19 |
return json.loads(base64.urlsafe_b64decode(payload).decode())
|
| 20 |
|
| 21 |
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.JSON())
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import base64
|
| 2 |
import json
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
| 5 |
import torch
|
| 6 |
from spaces.zero.client import _get_token
|
| 7 |
+
from fastapi import FastAPI
|
| 8 |
+
from fastapi.staticfiles import StaticFiles
|
| 9 |
+
import uvicorn
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
# FastAPI setup
|
| 13 |
+
app = FastAPI()
|
| 14 |
+
static_dir = Path('./static')
|
| 15 |
+
static_dir.mkdir(parents=True, exist_ok=True)
|
| 16 |
+
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
| 17 |
|
| 18 |
@spaces.GPU(duration=4*60) # Not possible with IP-based quotas
|
| 19 |
def inner():
|
|
|
|
| 28 |
return json.loads(base64.urlsafe_b64decode(payload).decode())
|
| 29 |
|
| 30 |
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.JSON())
|
| 31 |
+
|
| 32 |
+
# Mount Gradio app
|
| 33 |
+
app = gr.mount_gradio_app(app, demo, path="/", ssr_mode=False)
|
| 34 |
+
|
| 35 |
+
app.zerogpu = True
|
| 36 |
+
|
| 37 |
+
def start_server(app):
|
| 38 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 39 |
+
|
| 40 |
+
start_server.zerogpu = True
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
start_server(app)
|