Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,26 +5,27 @@ import torch
|
|
| 5 |
import io
|
| 6 |
import base64
|
| 7 |
|
|
|
|
| 8 |
pipe = QwenImageEditPlusPipeline.from_pretrained(
|
| 9 |
-
"Qwen/Qwen-Image-Edit-2511",
|
| 10 |
torch_dtype=torch.float16,
|
| 11 |
-
use_safetensors=True
|
|
|
|
| 12 |
)
|
| 13 |
-
pipe.
|
| 14 |
-
pipe.to("cpu") # CPU для free
|
| 15 |
|
| 16 |
def edit_image(image_b64, prompt):
|
| 17 |
image_b64 = image_b64.split(',')[1] if ',' in image_b64 else image_b64
|
| 18 |
image_bytes = base64.b64decode(image_b64)
|
| 19 |
-
image = Image.open(io.BytesIO(image_bytes)).convert('RGB')
|
| 20 |
result = pipe(image=image, prompt=prompt, num_inference_steps=15).images[0]
|
| 21 |
buffer = io.BytesIO()
|
| 22 |
-
result.save(buffer, format='
|
| 23 |
-
return 'data:image/
|
| 24 |
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=edit_image,
|
| 27 |
-
inputs=[gr.Textbox(lines=5, label="
|
| 28 |
-
outputs=gr.Image(
|
| 29 |
)
|
| 30 |
-
demo.launch()
|
|
|
|
| 5 |
import io
|
| 6 |
import base64
|
| 7 |
|
| 8 |
+
print("Loading model...")
|
| 9 |
pipe = QwenImageEditPlusPipeline.from_pretrained(
|
| 10 |
+
"Qwen/Qwen-Image-Edit-2511",
|
| 11 |
torch_dtype=torch.float16,
|
| 12 |
+
use_safetensors=True,
|
| 13 |
+
low_cpu_mem_usage=True
|
| 14 |
)
|
| 15 |
+
pipe.enable_sequential_cpu_offload() # Экономит RAM на CPU Space
|
|
|
|
| 16 |
|
| 17 |
def edit_image(image_b64, prompt):
|
| 18 |
image_b64 = image_b64.split(',')[1] if ',' in image_b64 else image_b64
|
| 19 |
image_bytes = base64.b64decode(image_b64)
|
| 20 |
+
image = Image.open(io.BytesIO(image_bytes)).resize((512,512)).convert('RGB') # Resize для скорости
|
| 21 |
result = pipe(image=image, prompt=prompt, num_inference_steps=15).images[0]
|
| 22 |
buffer = io.BytesIO()
|
| 23 |
+
result.save(buffer, format='JPEG', quality=90)
|
| 24 |
+
return 'data:image/jpeg;base64,' + base64.b64encode(buffer.getvalue()).decode()
|
| 25 |
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=edit_image,
|
| 28 |
+
inputs=[gr.Textbox(lines=5, placeholder="data:image;base64,...", label="Image base64"), gr.Textbox(label="Prompt")],
|
| 29 |
+
outputs=gr.Image(label="Result")
|
| 30 |
)
|
| 31 |
+
demo.launch(server_port=7860)
|