Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -58,7 +58,29 @@ with gr.Blocks(css=css) as demo:
|
|
58 |
with gr.Column(elem_id="col-container"):
|
59 |
gr.Markdown(" # Text-to-Image Gradio Template")
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
prompt = gr.Text(
|
63 |
label="Prompt",
|
64 |
show_label=False,
|
@@ -66,65 +88,61 @@ with gr.Blocks(css=css) as demo:
|
|
66 |
placeholder="Enter your prompt",
|
67 |
container=False,
|
68 |
)
|
69 |
-
|
70 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
visible=True,
|
80 |
-
)
|
81 |
-
|
82 |
-
seed = gr.Slider(
|
83 |
-
label="Seed",
|
84 |
-
minimum=0,
|
85 |
-
maximum=MAX_SEED,
|
86 |
-
step=1,
|
87 |
-
value=0,
|
88 |
-
)
|
89 |
-
|
90 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
91 |
-
|
92 |
-
with gr.Row():
|
93 |
-
width = gr.Slider(
|
94 |
-
label="Width",
|
95 |
-
minimum=256,
|
96 |
-
maximum=MAX_IMAGE_SIZE,
|
97 |
-
step=32,
|
98 |
-
value=512, # Default width for your model
|
99 |
-
)
|
100 |
-
|
101 |
-
height = gr.Slider(
|
102 |
-
label="Height",
|
103 |
-
minimum=256,
|
104 |
-
maximum=MAX_IMAGE_SIZE,
|
105 |
-
step=32,
|
106 |
-
value=512, # Default height for your model
|
107 |
)
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
minimum=0.0,
|
113 |
-
maximum=10.0,
|
114 |
-
step=0.1,
|
115 |
-
value=7.5, # Default guidance scale for your model
|
116 |
-
)
|
117 |
-
|
118 |
-
num_inference_steps = gr.Slider(
|
119 |
-
label="Number of inference steps",
|
120 |
-
minimum=1,
|
121 |
-
maximum=50,
|
122 |
step=1,
|
123 |
-
value=
|
124 |
)
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
run_button.click(
|
129 |
infer,
|
130 |
inputs=[
|
|
|
58 |
with gr.Column(elem_id="col-container"):
|
59 |
gr.Markdown(" # Text-to-Image Gradio Template")
|
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
|
68 |
+
def update_user_info(profile):
|
69 |
+
if profile is None:
|
70 |
+
return gr.Error("Please log in to access the application.")
|
71 |
+
return profile
|
72 |
+
|
73 |
+
# Update user_info when login_button is clicked
|
74 |
+
login_button.click(update_user_info, inputs=None, outputs=user_info)
|
75 |
+
|
76 |
+
# Check if user is authenticated before displaying the main interface
|
77 |
+
def check_auth(user_info):
|
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,
|
|
|
88 |
placeholder="Enter your prompt",
|
89 |
container=False,
|
90 |
)
|
|
|
91 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
92 |
+
result = gr.Image(label="Result", show_label=False)
|
93 |
+
|
94 |
+
with gr.Accordion("Advanced Settings", open=False):
|
95 |
+
negative_prompt = gr.Text(
|
96 |
+
label="Negative prompt",
|
97 |
+
max_lines=1,
|
98 |
+
placeholder="Enter a negative prompt",
|
99 |
+
visible=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
)
|
101 |
+
seed = gr.Slider(
|
102 |
+
label="Seed",
|
103 |
+
minimum=0,
|
104 |
+
maximum=MAX_SEED,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
step=1,
|
106 |
+
value=0,
|
107 |
)
|
108 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
109 |
+
with gr.Row():
|
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(
|
147 |
infer,
|
148 |
inputs=[
|