Spaces:
Runtime error
Runtime error
UdacityNoob
commited on
Commit
β’
0fdaa46
1
Parent(s):
c2a544b
Add support to run in Google Colab
Browse files
app.py
CHANGED
@@ -2,6 +2,16 @@ import os, torch
|
|
2 |
import gradio as gr
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# get hf user access token as an environment variable
|
6 |
TOKEN_KEY = os.getenv('AUTH_TOKEN')
|
7 |
|
@@ -23,9 +33,9 @@ def generate(prompt:str, seed:int, guidance:float, steps:int):
|
|
23 |
|
24 |
if device == "cuda":
|
25 |
device_name = torch.cuda.get_device_name(0)
|
26 |
-
print(device_name + " available
|
27 |
else:
|
28 |
-
print("Using CPU
|
29 |
|
30 |
# create the gradio UI
|
31 |
# set precision to 0 to round value to nearest int
|
@@ -40,5 +50,4 @@ demo = gr.Interface(
|
|
40 |
demo.queue(concurrency_count=3)
|
41 |
|
42 |
# launch demo
|
43 |
-
|
44 |
-
demo.launch()
|
2 |
import gradio as gr
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
|
5 |
+
# check if running in google colab environment
|
6 |
+
def is_google_colab():
|
7 |
+
try:
|
8 |
+
import google.colab
|
9 |
+
return True
|
10 |
+
except:
|
11 |
+
return False
|
12 |
+
|
13 |
+
is_colab = is_google_colab()
|
14 |
+
|
15 |
# get hf user access token as an environment variable
|
16 |
TOKEN_KEY = os.getenv('AUTH_TOKEN')
|
17 |
|
33 |
|
34 |
if device == "cuda":
|
35 |
device_name = torch.cuda.get_device_name(0)
|
36 |
+
print(device_name + " available! Using GPU π₯")
|
37 |
else:
|
38 |
+
print("Using CPUπ.")
|
39 |
|
40 |
# create the gradio UI
|
41 |
# set precision to 0 to round value to nearest int
|
50 |
demo.queue(concurrency_count=3)
|
51 |
|
52 |
# launch demo
|
53 |
+
demo.launch(debug=is_colab, share=is_colab)
|
|