Spaces:
Runtime error
Runtime error
add countdown timer
Browse files
app.py
CHANGED
@@ -21,6 +21,8 @@ from pymongo.mongo_client import MongoClient
|
|
21 |
from pymongo.server_api import ServerApi
|
22 |
import time
|
23 |
|
|
|
|
|
24 |
|
25 |
|
26 |
load_dotenv()
|
@@ -169,25 +171,72 @@ def generate_images(prompts, pw, model):
|
|
169 |
|
170 |
return image_paths, image_labels # Return both image paths and labels
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
with gr.Blocks() as demo:
|
173 |
gr.Markdown("# <center>Prompt de Resistance Image Generator</center>")
|
174 |
-
gr.
|
175 |
-
|
|
|
|
|
176 |
challenge_display = gr.Textbox(label="Challenge", value=get_challenge())
|
177 |
challenge_display.disabled = True
|
178 |
regenerate_btn = gr.Button("New Challenge")
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
text = gr.Textbox(label="What do you want to create?",
|
182 |
placeholder="Enter your text and then click on the \"Image Generate\" button")
|
|
|
183 |
model = gr.Dropdown(choices=["dall-e-2", "dall-e-3"], label="Model", value="dall-e-3")
|
|
|
184 |
show_labels = gr.Checkbox(label="Show Image Labels", value=False)
|
|
|
185 |
btn = gr.Button("Generate Images")
|
186 |
output_images = gr.Gallery(label="Image Outputs", show_label=True, columns=[3], rows=[1], object_fit="contain",
|
187 |
height="auto", allow_preview=False)
|
188 |
#trigger generation either through hitting enter in the text field, or clicking the button.
|
189 |
-
text.submit(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels], outputs=output_images, api_name="generate_image") # Generate an api endpoint in Gradio / HF
|
190 |
btn.click(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels], outputs=output_images, api_name=False)
|
|
|
191 |
# toggle hiding and showing of labels
|
192 |
show_labels.change(fn=update_labels, inputs=[show_labels], outputs=[output_images])
|
193 |
# generate new challenge
|
|
|
21 |
from pymongo.server_api import ServerApi
|
22 |
import time
|
23 |
|
24 |
+
# countdown stuff
|
25 |
+
from datetime import datetime, timedelta
|
26 |
|
27 |
|
28 |
load_dotenv()
|
|
|
171 |
|
172 |
return image_paths, image_labels # Return both image paths and labels
|
173 |
|
174 |
+
|
175 |
+
#timer stuff
|
176 |
+
timer_cancelled_global = False # when true, timer does not tick down
|
177 |
+
|
178 |
+
def countdown(seconds):
|
179 |
+
"""
|
180 |
+
This function takes the number of seconds as input and returns a string displaying the remaining time.
|
181 |
+
"""
|
182 |
+
target_time = datetime.now() + timedelta(seconds=int(seconds))
|
183 |
+
while target_time > datetime.now():
|
184 |
+
remaining_time = target_time - datetime.now()
|
185 |
+
remaining_seconds = int(remaining_time.total_seconds())
|
186 |
+
yield f"{remaining_seconds:02d}"
|
187 |
+
# Check if the countdown was cancelled
|
188 |
+
if timer_cancelled_global:
|
189 |
+
break
|
190 |
+
|
191 |
+
def stop_countdown():
|
192 |
+
"""
|
193 |
+
This function stops the countdown.
|
194 |
+
"""
|
195 |
+
global timer_cancelled_global
|
196 |
+
timer_cancelled_global = True
|
197 |
+
|
198 |
+
def reset_countdown(slider):
|
199 |
+
"""
|
200 |
+
This function resets the countdown.
|
201 |
+
"""
|
202 |
+
global timer_cancelled_global
|
203 |
+
timer_cancelled_global = False
|
204 |
+
return 60
|
205 |
+
|
206 |
+
|
207 |
+
|
208 |
with gr.Blocks() as demo:
|
209 |
gr.Markdown("# <center>Prompt de Resistance Image Generator</center>")
|
210 |
+
with gr.Accordion("Instructions & Tips",label="Instructions & Tips",open=False):
|
211 |
+
gr.Markdown("**Instructions**: To use this service, please enter the password. Then generate an image from the prompt field below in response to the challenge, then click the download arrow from the top right of the image to save it.")
|
212 |
+
gr.Markdown("**Tips**: Use adjectives (size,color,mood), specify the visual style (realistic,cartoon,8-bit), explain the point of view (from above,first person,wide angle) ")
|
213 |
+
pw = gr.Textbox(label="Password", type="password", placeholder="Enter the password to unlock the service")
|
214 |
challenge_display = gr.Textbox(label="Challenge", value=get_challenge())
|
215 |
challenge_display.disabled = True
|
216 |
regenerate_btn = gr.Button("New Challenge")
|
217 |
+
|
218 |
+
slider = gr.Slider(minimum=1, maximum=120, value=60,label="Countdown",info="Select duration in seconds")
|
219 |
+
with gr.Row():
|
220 |
+
countdown_button = gr.Button("Start")
|
221 |
+
stop_countdown_button = gr.Button("Stop")
|
222 |
+
reset_countdown_button = gr.Button("Reset")
|
223 |
+
countdown_button.click(fn=countdown, inputs=[slider], outputs=[slider])
|
224 |
+
stop_countdown_button.click(fn=stop_countdown)
|
225 |
+
reset_countdown_button.click(fn=reset_countdown,inputs=[slider],outputs=[slider])
|
226 |
+
|
227 |
text = gr.Textbox(label="What do you want to create?",
|
228 |
placeholder="Enter your text and then click on the \"Image Generate\" button")
|
229 |
+
|
230 |
model = gr.Dropdown(choices=["dall-e-2", "dall-e-3"], label="Model", value="dall-e-3")
|
231 |
+
|
232 |
show_labels = gr.Checkbox(label="Show Image Labels", value=False)
|
233 |
+
|
234 |
btn = gr.Button("Generate Images")
|
235 |
output_images = gr.Gallery(label="Image Outputs", show_label=True, columns=[3], rows=[1], object_fit="contain",
|
236 |
height="auto", allow_preview=False)
|
237 |
#trigger generation either through hitting enter in the text field, or clicking the button.
|
|
|
238 |
btn.click(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels], outputs=output_images, api_name=False)
|
239 |
+
text.submit(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels], outputs=output_images, api_name="generate_image") # Generate an api endpoint in Gradio / HF
|
240 |
# toggle hiding and showing of labels
|
241 |
show_labels.change(fn=update_labels, inputs=[show_labels], outputs=[output_images])
|
242 |
# generate new challenge
|