Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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():
|
| 11 |
+
return "ok"
|
| 12 |
+
|
| 13 |
+
def greet(request: gr.Request, n):
|
| 14 |
+
token = _get_token(request)
|
| 15 |
+
print(token)
|
| 16 |
+
assert inner() == "ok"
|
| 17 |
+
payload = token.split('.')[1]
|
| 18 |
+
payload = f"{payload}{'=' * ((4 - len(payload) % 4) % 4)}"
|
| 19 |
+
return json.loads(base64.urlsafe_b64decode(payload).decode())
|
| 20 |
+
|
| 21 |
+
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.JSON())
|
| 22 |
+
demo.launch(ssr_mode=False)
|