Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import torch
|
| 3 |
from PIL import Image
|
| 4 |
-
from transformers import AutoProcessor, AutoModelForCausalLM
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
device_map="auto",
|
| 13 |
trust_remote_code=True
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
else:
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
output = model.generate(**inputs)
|
| 24 |
-
image = processor.batch_decode(output, output_type="pil")[0]
|
| 25 |
-
return image
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=generate,
|
|
@@ -30,9 +33,9 @@ demo = gr.Interface(
|
|
| 30 |
gr.Textbox(label="Prompt"),
|
| 31 |
gr.Image(label="Input Image (optional)")
|
| 32 |
],
|
| 33 |
-
outputs=gr.Image(label="Generated Image"),
|
| 34 |
-
title="Qwen Image Edit Rapid AIO",
|
| 35 |
-
description="
|
| 36 |
)
|
| 37 |
|
| 38 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
+
MODEL_ID = "Phr00t/Qwen-Image-Edit-Rapid-AIO"
|
| 7 |
|
| 8 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
+
MODEL_ID,
|
| 10 |
+
torch_dtype=torch.float32,
|
| 11 |
+
safety_checker=None,
|
|
|
|
| 12 |
trust_remote_code=True
|
| 13 |
)
|
| 14 |
|
| 15 |
+
pipe.to("cpu")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def generate(prompt, image):
|
| 19 |
+
if image is None:
|
| 20 |
+
# text → image
|
| 21 |
+
result = pipe(prompt)
|
| 22 |
+
return result.images[0]
|
| 23 |
else:
|
| 24 |
+
# image editing mode
|
| 25 |
+
img = Image.fromarray(image)
|
| 26 |
+
result = pipe(prompt=prompt, image=img)
|
| 27 |
+
return result.images[0]
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
demo = gr.Interface(
|
| 31 |
fn=generate,
|
|
|
|
| 33 |
gr.Textbox(label="Prompt"),
|
| 34 |
gr.Image(label="Input Image (optional)")
|
| 35 |
],
|
| 36 |
+
outputs=gr.Image(label="Generated / Edited Image"),
|
| 37 |
+
title="Qwen Image Edit Rapid AIO (CPU Friendly)",
|
| 38 |
+
description="Works on CPU with Diffusers. Supports text-to-image AND image editing."
|
| 39 |
)
|
| 40 |
|
| 41 |
demo.launch()
|