Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
-
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
-
|
7 |
-
# Load the pipeline
|
8 |
-
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev")
|
9 |
-
pipe.load_lora_weights("EvanZhouDev/open-genmoji")
|
10 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
-
pipe = pipe.to(device)
|
12 |
|
13 |
MAX_SEED = np.iinfo(np.int32).max
|
14 |
MAX_IMAGE_SIZE = 1024
|
@@ -22,7 +16,17 @@ def infer(
|
|
22 |
height,
|
23 |
guidance_scale,
|
24 |
num_inference_steps,
|
|
|
25 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Handle seed randomization
|
27 |
if randomize_seed:
|
28 |
seed = random.randint(0, MAX_SEED)
|
@@ -60,8 +64,6 @@ with gr.Blocks(css=css) as demo:
|
|
60 |
|
61 |
# Add the LoginButton
|
62 |
login_button = gr.LoginButton()
|
63 |
-
|
64 |
-
# Placeholder for user profile information
|
65 |
user_info = gr.State()
|
66 |
|
67 |
# Function to update user_info upon login
|
@@ -73,14 +75,8 @@ with gr.Blocks(css=css) as demo:
|
|
73 |
# Update user_info when login_button is clicked
|
74 |
login_button.click(update_user_info, inputs=None, outputs=user_info)
|
75 |
|
76 |
-
#
|
77 |
-
|
78 |
-
if user_info is None:
|
79 |
-
return gr.Error("Please log in to access the application.")
|
80 |
-
return gr.update(visible=True)
|
81 |
-
|
82 |
-
# Main interface components
|
83 |
-
with gr.Row(visible=False) as main_interface:
|
84 |
prompt = gr.Text(
|
85 |
label="Prompt",
|
86 |
show_label=False,
|
@@ -91,56 +87,53 @@ with gr.Blocks(css=css) as demo:
|
|
91 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
92 |
result = gr.Image(label="Result", show_label=False)
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
)
|
101 |
-
|
102 |
-
label="
|
103 |
-
minimum=
|
104 |
-
maximum=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
step=1,
|
106 |
-
value=
|
107 |
)
|
108 |
-
|
109 |
-
|
110 |
-
width = gr.Slider(
|
111 |
-
label="Width",
|
112 |
-
minimum=256,
|
113 |
-
maximum=MAX_IMAGE_SIZE,
|
114 |
-
step=32,
|
115 |
-
value=512,
|
116 |
-
)
|
117 |
-
height = gr.Slider(
|
118 |
-
label="Height",
|
119 |
-
minimum=256,
|
120 |
-
maximum=MAX_IMAGE_SIZE,
|
121 |
-
step=32,
|
122 |
-
value=512,
|
123 |
-
)
|
124 |
-
with gr.Row():
|
125 |
-
guidance_scale = gr.Slider(
|
126 |
-
label="Guidance scale",
|
127 |
-
minimum=0.0,
|
128 |
-
maximum=10.0,
|
129 |
-
step=0.1,
|
130 |
-
value=7.5,
|
131 |
-
)
|
132 |
-
num_inference_steps = gr.Slider(
|
133 |
-
label="Number of inference steps",
|
134 |
-
minimum=1,
|
135 |
-
maximum=50,
|
136 |
-
step=1,
|
137 |
-
value=25,
|
138 |
-
)
|
139 |
-
|
140 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
141 |
-
|
142 |
-
# Display main interface if authenticated
|
143 |
-
user_info.change(check_auth, inputs=user_info, outputs=main_interface)
|
144 |
|
145 |
# Run inference when run_button is clicked
|
146 |
run_button.click(
|
@@ -154,6 +147,7 @@ with gr.Blocks(css=css) as demo:
|
|
154 |
height,
|
155 |
guidance_scale,
|
156 |
num_inference_steps,
|
|
|
157 |
],
|
158 |
outputs=[result, seed],
|
159 |
)
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
|
|
4 |
import torch
|
5 |
+
from diffusers import DiffusionPipeline
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
MAX_SEED = np.iinfo(np.int32).max
|
8 |
MAX_IMAGE_SIZE = 1024
|
|
|
16 |
height,
|
17 |
guidance_scale,
|
18 |
num_inference_steps,
|
19 |
+
user_info,
|
20 |
):
|
21 |
+
if user_info is None:
|
22 |
+
return "Please log in to generate images.", None
|
23 |
+
|
24 |
+
# Load the pipeline only when this function is called
|
25 |
+
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev")
|
26 |
+
pipe.load_lora_weights("EvanZhouDev/open-genmoji")
|
27 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
28 |
+
pipe = pipe.to(device)
|
29 |
+
|
30 |
# Handle seed randomization
|
31 |
if randomize_seed:
|
32 |
seed = random.randint(0, MAX_SEED)
|
|
|
64 |
|
65 |
# Add the LoginButton
|
66 |
login_button = gr.LoginButton()
|
|
|
|
|
67 |
user_info = gr.State()
|
68 |
|
69 |
# Function to update user_info upon login
|
|
|
75 |
# Update user_info when login_button is clicked
|
76 |
login_button.click(update_user_info, inputs=None, outputs=user_info)
|
77 |
|
78 |
+
# Main interface
|
79 |
+
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
prompt = gr.Text(
|
81 |
label="Prompt",
|
82 |
show_label=False,
|
|
|
87 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
88 |
result = gr.Image(label="Result", show_label=False)
|
89 |
|
90 |
+
with gr.Accordion("Advanced Settings", open=False):
|
91 |
+
negative_prompt = gr.Text(
|
92 |
+
label="Negative prompt",
|
93 |
+
max_lines=1,
|
94 |
+
placeholder="Enter a negative prompt",
|
95 |
+
visible=True,
|
96 |
+
)
|
97 |
+
seed = gr.Slider(
|
98 |
+
label="Seed",
|
99 |
+
minimum=0,
|
100 |
+
maximum=MAX_SEED,
|
101 |
+
step=1,
|
102 |
+
value=0,
|
103 |
+
)
|
104 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
105 |
+
with gr.Row():
|
106 |
+
width = gr.Slider(
|
107 |
+
label="Width",
|
108 |
+
minimum=256,
|
109 |
+
maximum=MAX_IMAGE_SIZE,
|
110 |
+
step=32,
|
111 |
+
value=512,
|
112 |
)
|
113 |
+
height = gr.Slider(
|
114 |
+
label="Height",
|
115 |
+
minimum=256,
|
116 |
+
maximum=MAX_IMAGE_SIZE,
|
117 |
+
step=32,
|
118 |
+
value=512,
|
119 |
+
)
|
120 |
+
with gr.Row():
|
121 |
+
guidance_scale = gr.Slider(
|
122 |
+
label="Guidance scale",
|
123 |
+
minimum=0.0,
|
124 |
+
maximum=10.0,
|
125 |
+
step=0.1,
|
126 |
+
value=7.5,
|
127 |
+
)
|
128 |
+
num_inference_steps = gr.Slider(
|
129 |
+
label="Number of inference steps",
|
130 |
+
minimum=1,
|
131 |
+
maximum=50,
|
132 |
step=1,
|
133 |
+
value=25,
|
134 |
)
|
135 |
+
|
136 |
+
gr.Examples(examples=examples, inputs=[prompt])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
# Run inference when run_button is clicked
|
139 |
run_button.click(
|
|
|
147 |
height,
|
148 |
guidance_scale,
|
149 |
num_inference_steps,
|
150 |
+
user_info,
|
151 |
],
|
152 |
outputs=[result, seed],
|
153 |
)
|