Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,26 +2,23 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import random
|
4 |
|
5 |
-
# import spaces #[uncomment to use ZeroGPU]
|
6 |
from diffusers import DiffusionPipeline
|
7 |
import torch
|
8 |
|
|
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
-
model_repo_id = "
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
else:
|
15 |
-
torch_dtype = torch.float32
|
16 |
|
|
|
17 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
18 |
pipe = pipe.to(device)
|
19 |
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
23 |
-
|
24 |
-
# @spaces.GPU #[uncomment to use ZeroGPU]
|
25 |
def infer(
|
26 |
prompt,
|
27 |
negative_prompt,
|
@@ -36,8 +33,9 @@ def infer(
|
|
36 |
if randomize_seed:
|
37 |
seed = random.randint(0, MAX_SEED)
|
38 |
|
39 |
-
generator = torch.Generator().manual_seed(seed)
|
40 |
|
|
|
41 |
image = pipe(
|
42 |
prompt=prompt,
|
43 |
negative_prompt=negative_prompt,
|
@@ -50,11 +48,10 @@ def infer(
|
|
50 |
|
51 |
return image, seed
|
52 |
|
53 |
-
|
54 |
examples = [
|
55 |
-
"Astronaut in a jungle,
|
56 |
-
"
|
57 |
-
"
|
58 |
]
|
59 |
|
60 |
css = """
|
@@ -66,7 +63,7 @@ css = """
|
|
66 |
|
67 |
with gr.Blocks(css=css) as demo:
|
68 |
with gr.Column(elem_id="col-container"):
|
69 |
-
gr.Markdown(" #
|
70 |
|
71 |
with gr.Row():
|
72 |
prompt = gr.Text(
|
@@ -105,7 +102,7 @@ with gr.Blocks(css=css) as demo:
|
|
105 |
minimum=256,
|
106 |
maximum=MAX_IMAGE_SIZE,
|
107 |
step=32,
|
108 |
-
value=
|
109 |
)
|
110 |
|
111 |
height = gr.Slider(
|
@@ -113,7 +110,7 @@ with gr.Blocks(css=css) as demo:
|
|
113 |
minimum=256,
|
114 |
maximum=MAX_IMAGE_SIZE,
|
115 |
step=32,
|
116 |
-
value=
|
117 |
)
|
118 |
|
119 |
with gr.Row():
|
@@ -122,7 +119,7 @@ with gr.Blocks(css=css) as demo:
|
|
122 |
minimum=0.0,
|
123 |
maximum=10.0,
|
124 |
step=0.1,
|
125 |
-
value=
|
126 |
)
|
127 |
|
128 |
num_inference_steps = gr.Slider(
|
@@ -130,7 +127,7 @@ with gr.Blocks(css=css) as demo:
|
|
130 |
minimum=1,
|
131 |
maximum=50,
|
132 |
step=1,
|
133 |
-
value=
|
134 |
)
|
135 |
|
136 |
gr.Examples(examples=examples, inputs=[prompt])
|
|
|
2 |
import numpy as np
|
3 |
import random
|
4 |
|
|
|
5 |
from diffusers import DiffusionPipeline
|
6 |
import torch
|
7 |
|
8 |
+
# Check device and set appropriate precision
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
model_repo_id = "fofr/sdxl-emoji" # New model URL
|
11 |
|
12 |
+
# Determine the appropriate dtype based on availability of GPU
|
13 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
|
|
|
|
14 |
|
15 |
+
# Load the new pipeline
|
16 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
17 |
pipe = pipe.to(device)
|
18 |
|
19 |
MAX_SEED = np.iinfo(np.int32).max
|
20 |
MAX_IMAGE_SIZE = 1024
|
21 |
|
|
|
|
|
22 |
def infer(
|
23 |
prompt,
|
24 |
negative_prompt,
|
|
|
33 |
if randomize_seed:
|
34 |
seed = random.randint(0, MAX_SEED)
|
35 |
|
36 |
+
generator = torch.Generator(device).manual_seed(seed)
|
37 |
|
38 |
+
# Generate the image
|
39 |
image = pipe(
|
40 |
prompt=prompt,
|
41 |
negative_prompt=negative_prompt,
|
|
|
48 |
|
49 |
return image, seed
|
50 |
|
|
|
51 |
examples = [
|
52 |
+
"Astronaut emoji in a jungle, vibrant colors, 4k",
|
53 |
+
"Emoji of a cat riding a skateboard",
|
54 |
+
"Emoji of a cake with flowers",
|
55 |
]
|
56 |
|
57 |
css = """
|
|
|
63 |
|
64 |
with gr.Blocks(css=css) as demo:
|
65 |
with gr.Column(elem_id="col-container"):
|
66 |
+
gr.Markdown(" # Emoji Generator Gradio Template")
|
67 |
|
68 |
with gr.Row():
|
69 |
prompt = gr.Text(
|
|
|
102 |
minimum=256,
|
103 |
maximum=MAX_IMAGE_SIZE,
|
104 |
step=32,
|
105 |
+
value=512,
|
106 |
)
|
107 |
|
108 |
height = gr.Slider(
|
|
|
110 |
minimum=256,
|
111 |
maximum=MAX_IMAGE_SIZE,
|
112 |
step=32,
|
113 |
+
value=512,
|
114 |
)
|
115 |
|
116 |
with gr.Row():
|
|
|
119 |
minimum=0.0,
|
120 |
maximum=10.0,
|
121 |
step=0.1,
|
122 |
+
value=7.5,
|
123 |
)
|
124 |
|
125 |
num_inference_steps = gr.Slider(
|
|
|
127 |
minimum=1,
|
128 |
maximum=50,
|
129 |
step=1,
|
130 |
+
value=20,
|
131 |
)
|
132 |
|
133 |
gr.Examples(examples=examples, inputs=[prompt])
|