Astridkraft commited on
Commit
ecfe07b
·
verified ·
1 Parent(s): 7fa98fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -12
app.py CHANGED
@@ -65,12 +65,16 @@ def text_to_image(prompt, steps, guidance_scale):
65
 
66
  pipe = load_txt2img()
67
 
 
 
 
68
  image = pipe(
69
  prompt=prompt,
70
  height=IMG_SIZE,
71
  width=IMG_SIZE,
72
  num_inference_steps=steps,
73
  guidance_scale=guidance_scale,
 
74
  ).images[0]
75
 
76
  end_time = time.time()
@@ -84,23 +88,29 @@ def text_to_image(prompt, steps, guidance_scale):
84
  traceback.print_exc()
85
  return None
86
 
87
- def img_to_image(image, prompt, strength, steps, guidance_scale):
88
  try:
89
  if image is None:
90
  return None
91
 
92
  print(f"Image-to-Image mit Strength: {strength}, Steps: {steps}, Guidance: {guidance_scale}")
 
93
  start_time = time.time()
94
 
95
  pipe = load_img2img()
96
  img_resized = image.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
97
 
 
 
 
98
  result = pipe(
99
  prompt=prompt,
 
100
  image=img_resized,
101
  strength=strength,
102
  num_inference_steps=steps,
103
- guidance_scale=guidance_scale
 
104
  )
105
 
106
  end_time = time.time()
@@ -137,14 +147,14 @@ with gr.Blocks() as app:
137
  with gr.Column():
138
  txt_guidance = gr.Slider(
139
  minimum=1.0, maximum=20.0, value=7.5, step=0.5,
140
- label="Guidance Scale (Prompt-Treue)"
141
  )
142
 
143
  with gr.Row():
144
  gr.Markdown(
145
  "**Parameter-Erklärung:** "
146
  "• **Steps:** Mehr = bessere Qualität, aber langsamer "
147
- "• **Guidance:** Höher = stärkere Prompt-Treue, kann verzerren "
148
  )
149
 
150
  generate_btn = gr.Button("🎨 Bild generieren", variant="primary")
@@ -171,11 +181,18 @@ with gr.Blocks() as app:
171
  )
172
 
173
  with gr.Row():
174
- img_prompt = gr.Textbox(
175
- placeholder="background only: winter forest, keep girl and snowman unchanged",
176
- lines=2,
177
- label="Transformations-Prompt (Englisch)"
178
- )
 
 
 
 
 
 
 
179
 
180
  with gr.Row():
181
  with gr.Column():
@@ -191,7 +208,7 @@ with gr.Blocks() as app:
191
  with gr.Column():
192
  img_guidance = gr.Slider(
193
  minimum=1.0, maximum=20.0, value=7.5, step=0.5,
194
- label="Guidance Scale (Prompt-Treue)"
195
  )
196
 
197
  with gr.Row():
@@ -199,7 +216,8 @@ with gr.Blocks() as app:
199
  "**Parameter-Erklärung:** "
200
  "• **Strength:** Niedrig = behält Original, Hoch = starke Veränderung "
201
  "• **Steps:** Mehr = bessere Qualität, aber langsamer "
202
- "• **Guidance:** Höher = stärkere Prompt-Treue "
 
203
  )
204
 
205
  transform_btn = gr.Button("🔄 Bild transformieren", variant="primary")
@@ -212,7 +230,7 @@ with gr.Blocks() as app:
212
 
213
  transform_btn.click(
214
  fn=img_to_image,
215
- inputs=[img_input, img_prompt, strength_slider, img_steps, img_guidance],
216
  outputs=img_output,
217
  concurrency_limit=1
218
  )
 
65
 
66
  pipe = load_txt2img()
67
 
68
+ # Seed für Reproduzierbarkeit (-1 = zufällig)
69
+ generator = torch.Generator(device=device).manual_seed(-1)
70
+
71
  image = pipe(
72
  prompt=prompt,
73
  height=IMG_SIZE,
74
  width=IMG_SIZE,
75
  num_inference_steps=steps,
76
  guidance_scale=guidance_scale,
77
+ generator=generator
78
  ).images[0]
79
 
80
  end_time = time.time()
 
88
  traceback.print_exc()
89
  return None
90
 
91
+ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale):
92
  try:
93
  if image is None:
94
  return None
95
 
96
  print(f"Image-to-Image mit Strength: {strength}, Steps: {steps}, Guidance: {guidance_scale}")
97
+ print(f"Negative Prompt: {neg_prompt}")
98
  start_time = time.time()
99
 
100
  pipe = load_img2img()
101
  img_resized = image.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
102
 
103
+ # Seed für Reproduzierbarkeit (-1 = zufällig)
104
+ generator = torch.Generator(device=device).manual_seed(-1)
105
+
106
  result = pipe(
107
  prompt=prompt,
108
+ negative_prompt=neg_prompt,
109
  image=img_resized,
110
  strength=strength,
111
  num_inference_steps=steps,
112
+ guidance_scale=guidance_scale,
113
+ generator=generator
114
  )
115
 
116
  end_time = time.time()
 
147
  with gr.Column():
148
  txt_guidance = gr.Slider(
149
  minimum=1.0, maximum=20.0, value=7.5, step=0.5,
150
+ label="Guidance Scale (Prompt-Treue vs. Verzerrung)"
151
  )
152
 
153
  with gr.Row():
154
  gr.Markdown(
155
  "**Parameter-Erklärung:** "
156
  "• **Steps:** Mehr = bessere Qualität, aber langsamer "
157
+ "• **Guidance:** Niedrig = weniger Verzerrung, Hoch = mehr KI-Fantasie "
158
  )
159
 
160
  generate_btn = gr.Button("🎨 Bild generieren", variant="primary")
 
181
  )
182
 
183
  with gr.Row():
184
+ with gr.Column():
185
+ img_prompt = gr.Textbox(
186
+ placeholder="background only: winter forest, keep girl and snowman unchanged",
187
+ lines=2,
188
+ label="Transformations-Prompt (Englisch)"
189
+ )
190
+ with gr.Column():
191
+ img_neg_prompt = gr.Textbox(
192
+ placeholder="blurry, deformed, ugly, bad anatomy, distorted faces",
193
+ lines=2,
194
+ label="Negativ-Prompt (was vermieden werden soll)"
195
+ )
196
 
197
  with gr.Row():
198
  with gr.Column():
 
208
  with gr.Column():
209
  img_guidance = gr.Slider(
210
  minimum=1.0, maximum=20.0, value=7.5, step=0.5,
211
+ label="Guidance Scale (Prompt-Treue vs. Verzerrung)"
212
  )
213
 
214
  with gr.Row():
 
216
  "**Parameter-Erklärung:** "
217
  "• **Strength:** Niedrig = behält Original, Hoch = starke Veränderung "
218
  "• **Steps:** Mehr = bessere Qualität, aber langsamer "
219
+ "• **Guidance:** Niedrig = weniger Verzerrung, Hoch = mehr KI-Fantasie "
220
+ "• **Negativ-Prompt:** Beschreibt was NICHT im Bild sein soll "
221
  )
222
 
223
  transform_btn = gr.Button("🔄 Bild transformieren", variant="primary")
 
230
 
231
  transform_btn.click(
232
  fn=img_to_image,
233
+ inputs=[img_input, img_prompt, img_neg_prompt, strength_slider, img_steps, img_guidance],
234
  outputs=img_output,
235
  concurrency_limit=1
236
  )