Spaces:
Running
Running
demo update
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
zero = torch.Tensor([0]).cuda()
|
| 6 |
print(zero.device) # <-- 'cpu' 🤔
|
|
@@ -10,5 +11,23 @@ def greet(n):
|
|
| 10 |
print(zero.device) # <-- 'cuda:0' 🤗
|
| 11 |
return f"Hello {zero + n} Tensor"
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
zero = torch.Tensor([0]).cuda()
|
| 7 |
print(zero.device) # <-- 'cpu' 🤔
|
|
|
|
| 11 |
print(zero.device) # <-- 'cuda:0' 🤗
|
| 12 |
return f"Hello {zero + n} Tensor"
|
| 13 |
|
| 14 |
+
def clear():
|
| 15 |
+
return ""
|
| 16 |
+
|
| 17 |
+
def random_number():
|
| 18 |
+
return random.uniform(0, 100)
|
| 19 |
+
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
input_text = gr.Number(label="Input Number")
|
| 22 |
+
output_text = gr.Textbox(label="Output Text")
|
| 23 |
+
|
| 24 |
+
with gr.Row():
|
| 25 |
+
retrieve_button = gr.Button("Retrieve")
|
| 26 |
+
clear_button = gr.Button("Clear")
|
| 27 |
+
random_button = gr.Button("Random")
|
| 28 |
+
|
| 29 |
+
retrieve_button.click(greet, inputs=input_text, outputs=output_text)
|
| 30 |
+
clear_button.click(clear, outputs=input_text)
|
| 31 |
+
random_button.click(random_number, outputs=input_text)
|
| 32 |
+
|
| 33 |
+
demo.launch()
|