cbensimon HF staff commited on
Commit
2db09df
·
verified ·
1 Parent(s): f32140f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,18 +1,21 @@
 
 
 
1
  import gradio as gr
2
  import spaces
3
  import torch
4
  from spaces.zero.client import _get_token
5
 
6
- zero = torch.Tensor([0]).cuda()
7
- print(zero.device) # <-- 'cpu' 🤔
8
-
9
- @spaces.GPU(duration=4*60)
10
  def inner():
11
  return "ok"
12
 
13
  def greet(request: gr.Request, n):
14
  assert inner() == "ok"
15
- return _get_token(request)
 
 
 
16
 
17
- demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
18
  demo.launch()
 
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
  assert inner() == "ok"
15
+ token = _get_token(request)
16
+ payload = token.split('.')[1]
17
+ payload = f"{payload}{'=' * ((4 - len(payload) % 4) % 4)}"
18
+ return json.loads(base64.urlsafe_b64decode(payload).decode())
19
 
20
+ demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.JSON())
21
  demo.launch()