Spaces:
Sleeping
Sleeping
Tobias Geisler commited on
Commit ·
200e5b9
1
Parent(s): 7f24ec8
reintroduce generation timeout
Browse files
app.py
CHANGED
|
@@ -16,6 +16,11 @@ APP_PASSWORD = os.getenv("APP_PASSWORD")
|
|
| 16 |
if APP_PASSWORD is None:
|
| 17 |
raise ValueError("Die Umgebungsvariable APP_PASSWORD ist nicht gesetzt.")
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
last_generation_time = defaultdict(float)
|
| 20 |
|
| 21 |
def enhance_prompt(original_prompt):
|
|
@@ -41,8 +46,8 @@ def generate_image(prompt, use_magic_prompt, style, user_id, password):
|
|
| 41 |
return "Falsches Passwort. Bitte versuche es erneut.", None
|
| 42 |
|
| 43 |
current_time = time.time()
|
| 44 |
-
if current_time - last_generation_time[user_id] <
|
| 45 |
-
return "Bitte warte
|
| 46 |
|
| 47 |
if use_magic_prompt:
|
| 48 |
prompt = enhance_prompt(prompt)
|
|
@@ -85,7 +90,7 @@ examples = [
|
|
| 85 |
|
| 86 |
with gr.Blocks() as demo:
|
| 87 |
gr.Markdown("# codora DALL-E 3 Bildgenerator")
|
| 88 |
-
gr.Markdown("Gib einen Bildprompt ein und verwende optional die magische Prompt-Funktion, um ihn zu verbessern. Du kannst nur ein Bild alle
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
with gr.Column(scale=1):
|
|
|
|
| 16 |
if APP_PASSWORD is None:
|
| 17 |
raise ValueError("Die Umgebungsvariable APP_PASSWORD ist nicht gesetzt.")
|
| 18 |
|
| 19 |
+
|
| 20 |
+
GENERATION_TIMEOUT = float(os.getenv("GENERATION_TIMEOUT"))
|
| 21 |
+
if GENERATION_TIMEOUT is None:
|
| 22 |
+
GENERATION_TIMEOUT = 60
|
| 23 |
+
|
| 24 |
last_generation_time = defaultdict(float)
|
| 25 |
|
| 26 |
def enhance_prompt(original_prompt):
|
|
|
|
| 46 |
return "Falsches Passwort. Bitte versuche es erneut.", None
|
| 47 |
|
| 48 |
current_time = time.time()
|
| 49 |
+
if current_time - last_generation_time[user_id] < GENERATION_TIMEOUT:
|
| 50 |
+
return f"Bitte warte {GENERATION_TIMEOUT} Sekunden zwischen den Bildgenerierungen.", None
|
| 51 |
|
| 52 |
if use_magic_prompt:
|
| 53 |
prompt = enhance_prompt(prompt)
|
|
|
|
| 90 |
|
| 91 |
with gr.Blocks() as demo:
|
| 92 |
gr.Markdown("# codora DALL-E 3 Bildgenerator")
|
| 93 |
+
gr.Markdown(f"Gib einen Bildprompt ein und verwende optional die magische Prompt-Funktion, um ihn zu verbessern. Du kannst nur ein Bild alle {GENERATION_TIMEOUT} Sekunden generieren.")
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
with gr.Column(scale=1):
|