Dervlex commited on
Commit
aac016b
·
verified ·
1 Parent(s): bc083b3

Delete test_qwen_edit.py

Browse files
Files changed (1) hide show
  1. test_qwen_edit.py +0 -220
test_qwen_edit.py DELETED
@@ -1,220 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Qwen Image Edit Test Script mit UI
4
- Testet die offizielle Qwen-Image-Edit-2509 Implementation
5
- """
6
-
7
- import os
8
- import sys
9
- import torch
10
- from PIL import Image
11
- import gradio as gr
12
- from diffusers import QwenImageEditPipeline
13
- import tempfile
14
-
15
- class QwenImageEditTester:
16
- def __init__(self):
17
- self.pipeline = None
18
- self.device = "cuda" if torch.cuda.is_available() else "cpu"
19
- print(f"Using device: {self.device}")
20
-
21
- def load_pipeline(self):
22
- """Lädt die Qwen-Image-Edit Pipeline"""
23
- try:
24
- print("Loading Qwen-Image-Edit pipeline...")
25
- self.pipeline = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit")
26
- print("Pipeline loaded successfully!")
27
-
28
- # Pipeline konfigurieren
29
- self.pipeline.to(torch.bfloat16)
30
- self.pipeline.to(self.device)
31
- self.pipeline.set_progress_bar_config(disable=None)
32
-
33
- print("Pipeline configured successfully!")
34
- return "✅ Pipeline erfolgreich geladen!"
35
-
36
- except Exception as e:
37
- error_msg = f"❌ Fehler beim Laden der Pipeline: {str(e)}"
38
- print(error_msg)
39
- return error_msg
40
-
41
- def test_image_edit(self, image, prompt, cfg_scale, steps, seed, negative_prompt):
42
- """Testet die Bildbearbeitung mit verschiedenen Einstellungen"""
43
- if self.pipeline is None:
44
- return None, "❌ Pipeline nicht geladen! Bitte zuerst 'Pipeline laden' klicken."
45
-
46
- if image is None:
47
- return None, "❌ Bitte ein Bild hochladen!"
48
-
49
- try:
50
- print(f"Testing with: CFG={cfg_scale}, Steps={steps}, Seed={seed}")
51
-
52
- # Bild konvertieren falls nötig
53
- if isinstance(image, str):
54
- image = Image.open(image)
55
-
56
- # RGB konvertieren
57
- image = image.convert("RGB")
58
-
59
- # Generator für deterministische Ergebnisse
60
- generator = torch.manual_seed(seed) if seed > 0 else None
61
-
62
- # Pipeline Inputs
63
- inputs = {
64
- "image": image,
65
- "prompt": prompt,
66
- "generator": generator,
67
- "true_cfg_scale": float(cfg_scale),
68
- "negative_prompt": negative_prompt if negative_prompt.strip() else " ",
69
- "num_inference_steps": int(steps),
70
- }
71
-
72
- print(f"Pipeline inputs: {inputs}")
73
-
74
- # Inference
75
- with torch.inference_mode():
76
- output = self.pipeline(**inputs)
77
- result_image = output.images[0]
78
-
79
- print("✅ Bildbearbeitung erfolgreich!")
80
- return result_image, "✅ Bildbearbeitung erfolgreich!"
81
-
82
- except Exception as e:
83
- error_msg = f"❌ Fehler bei der Bildbearbeitung: {str(e)}"
84
- print(error_msg)
85
- return None, error_msg
86
-
87
- def create_ui(self):
88
- """Erstellt die Gradio UI"""
89
-
90
- with gr.Blocks(title="Qwen Image Edit Test", theme=gr.themes.Soft()) as demo:
91
- gr.Markdown("# 🎨 Qwen Image Edit Test")
92
- gr.Markdown("Testet die offizielle Qwen-Image-Edit-2509 Implementation")
93
-
94
- with gr.Row():
95
- with gr.Column():
96
- # Pipeline Status
97
- pipeline_status = gr.Textbox(
98
- label="Pipeline Status",
99
- value="Pipeline nicht geladen",
100
- interactive=False
101
- )
102
-
103
- load_btn = gr.Button("🔄 Pipeline laden", variant="primary")
104
-
105
- # Bild Upload
106
- input_image = gr.Image(
107
- label="Input Bild",
108
- type="pil",
109
- height=300
110
- )
111
-
112
- # Prompt
113
- prompt = gr.Textbox(
114
- label="Prompt",
115
- value="Change the style of this image into realistic photography",
116
- lines=3
117
- )
118
-
119
- # Negative Prompt
120
- negative_prompt = gr.Textbox(
121
- label="Negative Prompt",
122
- value=" ",
123
- lines=2
124
- )
125
-
126
- with gr.Column():
127
- # Parameter
128
- cfg_scale = gr.Slider(
129
- label="CFG Scale",
130
- minimum=1.0,
131
- maximum=10.0,
132
- value=4.0,
133
- step=0.1
134
- )
135
-
136
- steps = gr.Slider(
137
- label="Steps",
138
- minimum=1,
139
- maximum=100,
140
- value=50,
141
- step=1
142
- )
143
-
144
- seed = gr.Number(
145
- label="Seed",
146
- value=0,
147
- precision=0
148
- )
149
-
150
- # Buttons
151
- generate_btn = gr.Button("🎨 Bild bearbeiten", variant="primary")
152
-
153
- # Output
154
- output_image = gr.Image(
155
- label="Output Bild",
156
- height=300
157
- )
158
-
159
- output_status = gr.Textbox(
160
- label="Status",
161
- interactive=False
162
- )
163
-
164
- # Event Handlers
165
- load_btn.click(
166
- fn=self.load_pipeline,
167
- outputs=[pipeline_status]
168
- )
169
-
170
- generate_btn.click(
171
- fn=self.test_image_edit,
172
- inputs=[
173
- input_image,
174
- prompt,
175
- cfg_scale,
176
- steps,
177
- seed,
178
- negative_prompt
179
- ],
180
- outputs=[output_image, output_status]
181
- )
182
-
183
- # Beispiel Prompts
184
- gr.Markdown("""
185
- ### 💡 Beispiel Prompts:
186
- - "Change the style of this image into realistic photography"
187
- - "Make this image look like a watercolor painting"
188
- - "Convert this to a cartoon style"
189
- - "Change the background to a beach scene"
190
- """)
191
-
192
- return demo
193
-
194
- def main():
195
- """Hauptfunktion"""
196
- print("🚀 Starte Qwen Image Edit Test...")
197
-
198
- # Prüfe CUDA
199
- if torch.cuda.is_available():
200
- print(f"✅ CUDA verfügbar: {torch.cuda.get_device_name()}")
201
- print(f"✅ CUDA Memory: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.1f} GB")
202
- else:
203
- print("⚠️ CUDA nicht verfügbar, verwende CPU")
204
-
205
- # Tester erstellen
206
- tester = QwenImageEditTester()
207
-
208
- # UI erstellen und starten
209
- demo = tester.create_ui()
210
-
211
- print("🌐 Starte Web-Interface...")
212
- demo.launch(
213
- server_name="0.0.0.0",
214
- server_port=7860,
215
- share=False,
216
- show_error=True
217
- )
218
-
219
- if __name__ == "__main__":
220
- main()