Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -45,19 +45,18 @@ def translate_if_korean(text):
|
|
45 |
return translator(text)[0]['translation_text']
|
46 |
return text
|
47 |
|
48 |
-
#
|
49 |
@spaces.GPU(duration=25)
|
50 |
-
def generate_image(prompt, seed=
|
51 |
-
|
52 |
prompt = translate_if_korean(prompt)
|
53 |
|
54 |
-
if randomize_seed
|
|
|
55 |
seed = random.randint(0, MAX_SEED)
|
56 |
generator = torch.Generator().manual_seed(seed)
|
57 |
|
58 |
start_time = time.time()
|
59 |
|
60 |
-
# Only generate the last image in the sequence
|
61 |
for img in pipe.generate_images(
|
62 |
prompt=prompt,
|
63 |
guidance_scale=0,
|
@@ -69,9 +68,13 @@ def generate_image(prompt, seed=42, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT,
|
|
69 |
latency = f"Processing Time: {(time.time()-start_time):.2f} seconds"
|
70 |
yield img, seed, latency
|
71 |
|
72 |
-
#
|
|
|
|
|
|
|
|
|
73 |
examples = [
|
74 |
-
"๋น๋ ์๋์ฒผ์ ์ ๋๋ฉ์ด์
์ผ๋ฌ์คํธ๋ ์ด์
",
|
75 |
"A steampunk owl wearing Victorian-era clothing and reading a mechanical book",
|
76 |
"A floating island made of books with waterfalls of knowledge cascading down",
|
77 |
"A bioluminescent forest where mushrooms glow like neon signs in a cyberpunk city",
|
@@ -88,7 +91,6 @@ footer {
|
|
88 |
# --- Gradio UI ---
|
89 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
90 |
with gr.Column(elem_id="app-container"):
|
91 |
-
|
92 |
with gr.Row():
|
93 |
with gr.Column(scale=3):
|
94 |
result = gr.Image(label=english_labels["Generated Image"], show_label=False, interactive=False)
|
@@ -107,7 +109,7 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
107 |
latency = gr.Text(show_label=False)
|
108 |
with gr.Row():
|
109 |
seed = gr.Number(label=english_labels["Seed"], value=42, precision=0)
|
110 |
-
randomize_seed = gr.Checkbox(label=english_labels["Randomize Seed"], value=
|
111 |
with gr.Row():
|
112 |
width = gr.Slider(label=english_labels["Width"], minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_WIDTH)
|
113 |
height = gr.Slider(label=english_labels["Height"], minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_HEIGHT)
|
@@ -118,13 +120,13 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
118 |
with gr.Row():
|
119 |
gr.Examples(
|
120 |
examples=examples,
|
121 |
-
fn=
|
122 |
inputs=[prompt],
|
123 |
outputs=[result, seed],
|
124 |
-
cache_examples=
|
125 |
)
|
126 |
|
127 |
-
# Event handling
|
128 |
enhanceBtn.click(
|
129 |
fn=generate_image,
|
130 |
inputs=[prompt, seed, width, height],
|
@@ -145,5 +147,4 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
145 |
queue=False
|
146 |
)
|
147 |
|
148 |
-
# Launch the app
|
149 |
demo.launch()
|
|
|
45 |
return translator(text)[0]['translation_text']
|
46 |
return text
|
47 |
|
48 |
+
# Modified inference function to always use random seed for examples
|
49 |
@spaces.GPU(duration=25)
|
50 |
+
def generate_image(prompt, seed=None, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, randomize_seed=True, num_inference_steps=DEFAULT_INFERENCE_STEPS):
|
|
|
51 |
prompt = translate_if_korean(prompt)
|
52 |
|
53 |
+
# Always generate a random seed if none provided or randomize_seed is True
|
54 |
+
if seed is None or randomize_seed:
|
55 |
seed = random.randint(0, MAX_SEED)
|
56 |
generator = torch.Generator().manual_seed(seed)
|
57 |
|
58 |
start_time = time.time()
|
59 |
|
|
|
60 |
for img in pipe.generate_images(
|
61 |
prompt=prompt,
|
62 |
guidance_scale=0,
|
|
|
68 |
latency = f"Processing Time: {(time.time()-start_time):.2f} seconds"
|
69 |
yield img, seed, latency
|
70 |
|
71 |
+
# Function specifically for examples that always uses random seeds
|
72 |
+
def generate_example_image(prompt):
|
73 |
+
return generate_image(prompt, randomize_seed=True)
|
74 |
+
|
75 |
+
# Example prompts
|
76 |
examples = [
|
77 |
+
"๋น๋ ์๋์ฒผ์ ์ ๋๋ฉ์ด์
์ผ๋ฌ์คํธ๋ ์ด์
",
|
78 |
"A steampunk owl wearing Victorian-era clothing and reading a mechanical book",
|
79 |
"A floating island made of books with waterfalls of knowledge cascading down",
|
80 |
"A bioluminescent forest where mushrooms glow like neon signs in a cyberpunk city",
|
|
|
91 |
# --- Gradio UI ---
|
92 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
93 |
with gr.Column(elem_id="app-container"):
|
|
|
94 |
with gr.Row():
|
95 |
with gr.Column(scale=3):
|
96 |
result = gr.Image(label=english_labels["Generated Image"], show_label=False, interactive=False)
|
|
|
109 |
latency = gr.Text(show_label=False)
|
110 |
with gr.Row():
|
111 |
seed = gr.Number(label=english_labels["Seed"], value=42, precision=0)
|
112 |
+
randomize_seed = gr.Checkbox(label=english_labels["Randomize Seed"], value=True)
|
113 |
with gr.Row():
|
114 |
width = gr.Slider(label=english_labels["Width"], minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_WIDTH)
|
115 |
height = gr.Slider(label=english_labels["Height"], minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=DEFAULT_HEIGHT)
|
|
|
120 |
with gr.Row():
|
121 |
gr.Examples(
|
122 |
examples=examples,
|
123 |
+
fn=generate_example_image, # Use the example-specific function
|
124 |
inputs=[prompt],
|
125 |
outputs=[result, seed],
|
126 |
+
cache_examples=False # Disable caching to ensure new generation each time
|
127 |
)
|
128 |
|
129 |
+
# Event handling
|
130 |
enhanceBtn.click(
|
131 |
fn=generate_image,
|
132 |
inputs=[prompt, seed, width, height],
|
|
|
147 |
queue=False
|
148 |
)
|
149 |
|
|
|
150 |
demo.launch()
|