Astridkraft commited on
Commit
17ba4f0
·
verified ·
1 Parent(s): 5eae137

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -26
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py - OPTIMIERTE VERSION
2
  import gradio as gr
3
  from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
4
  import torch
@@ -8,8 +8,8 @@ import time
8
  # === OPTIMIERTE EINSTELLUNGEN ===
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
  torch_dtype = torch.float16 if device == "cuda" else torch.float32
11
- IMG_SIZE = 512 #320 # Bessere Qualität aber noch schnell
12
- STEPS = 35 #20 # Mehr Schritte für bessere Qualität
13
 
14
  print(f"Running on: {device}")
15
 
@@ -56,13 +56,12 @@ def text_to_image(prompt):
56
 
57
  pipe = load_txt2img()
58
 
59
- # Optimierte Generierung für bessere Qualität
60
  image = pipe(
61
  prompt=prompt,
62
  height=IMG_SIZE,
63
  width=IMG_SIZE,
64
  num_inference_steps=STEPS,
65
- guidance_scale=7.5, # Standard für bessere Qualität
66
  ).images[0]
67
 
68
  end_time = time.time()
@@ -76,13 +75,14 @@ def text_to_image(prompt):
76
  traceback.print_exc()
77
  return None
78
 
79
- # IMAGE-TO-IMAGE FUNKTION FIXEN:
80
- def img_to_image(image, prompt="", strength=0.6): # Strength Range anpassen
81
  try:
82
  if image is None:
83
  return None
84
 
85
  print(f"Image-to-Image mit Strength: {strength}")
 
 
86
  pipe = load_img2img()
87
  img_resized = image.convert("RGB").resize((512, 512))
88
 
@@ -94,20 +94,6 @@ def img_to_image(image, prompt="", strength=0.6): # Strength Range anpassen
94
  guidance_scale=7.5
95
  )
96
 
97
- print("✅ Bild 100% generiert - sende an UI")
98
- return result.images[0]
99
-
100
- except Exception as e:
101
- print(f"❌ Fehler: {e}")
102
- return None
103
-
104
- # SLIDER ANPASSEN:
105
- strength_slider = gr.Slider(
106
- 0.5, 0.8, 0.6, # Jetzt ab 0.5 möglich!
107
- label="Stärke der Veränderung"
108
- )
109
-
110
-
111
  end_time = time.time()
112
  print(f"✅ Bild transformiert in {end_time - start_time:.2f} Sekunden")
113
 
@@ -155,23 +141,23 @@ with gr.Blocks() as app:
155
 
156
  with gr.Row():
157
  img_prompt = gr.Textbox(
158
- placeholder="z.B. convert to winter landscape with snow",
159
  lines=2,
160
  label="Transformations-Prompt (Englisch)"
161
  )
162
 
163
  with gr.Row():
164
  strength_slider = gr.Slider(
165
- 0.6, 0.9, 0.75,
166
  label="Stärke der Veränderung"
167
  )
168
 
169
  with gr.Row():
170
  gr.Markdown(
171
  "**Stärke-Einstellung:** "
172
- "• **0.6-0.7:** Behält mehr vom Original bei "
173
- "• **0.75:** Gute Balance (empfohlen) "
174
- "• **0.8-0.9:** Stärkere Veränderungen"
175
  )
176
 
177
  transform_btn = gr.Button("🔄 Bild transformieren", variant="primary")
 
1
+ # app.py - KORRIGIERTE VERSION
2
  import gradio as gr
3
  from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
4
  import torch
 
8
  # === OPTIMIERTE EINSTELLUNGEN ===
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
  torch_dtype = torch.float16 if device == "cuda" else torch.float32
11
+ IMG_SIZE = 512
12
+ STEPS = 35
13
 
14
  print(f"Running on: {device}")
15
 
 
56
 
57
  pipe = load_txt2img()
58
 
 
59
  image = pipe(
60
  prompt=prompt,
61
  height=IMG_SIZE,
62
  width=IMG_SIZE,
63
  num_inference_steps=STEPS,
64
+ guidance_scale=7.5,
65
  ).images[0]
66
 
67
  end_time = time.time()
 
75
  traceback.print_exc()
76
  return None
77
 
78
+ def img_to_image(image, prompt="", strength=0.6):
 
79
  try:
80
  if image is None:
81
  return None
82
 
83
  print(f"Image-to-Image mit Strength: {strength}")
84
+ start_time = time.time()
85
+
86
  pipe = load_img2img()
87
  img_resized = image.convert("RGB").resize((512, 512))
88
 
 
94
  guidance_scale=7.5
95
  )
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  end_time = time.time()
98
  print(f"✅ Bild transformiert in {end_time - start_time:.2f} Sekunden")
99
 
 
141
 
142
  with gr.Row():
143
  img_prompt = gr.Textbox(
144
+ placeholder="background only: winter forest, keep girl and snowman unchanged",
145
  lines=2,
146
  label="Transformations-Prompt (Englisch)"
147
  )
148
 
149
  with gr.Row():
150
  strength_slider = gr.Slider(
151
+ 0.5, 0.8, 0.6, # Jetzt ab 0.5 möglich!
152
  label="Stärke der Veränderung"
153
  )
154
 
155
  with gr.Row():
156
  gr.Markdown(
157
  "**Stärke-Einstellung:** "
158
+ "• **0.5-0.6:** Behält fast alles Original bei "
159
+ "• **0.65-0.7:** Gute Balance "
160
+ "• **0.75-0.8:** Stärkere Veränderungen"
161
  )
162
 
163
  transform_btn = gr.Button("🔄 Bild transformieren", variant="primary")