Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,19 @@
|
|
| 1 |
import torch
|
| 2 |
-
|
| 3 |
-
from qwen_vl_utils import process_vision_info
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
model_id = "
|
| 8 |
-
|
| 9 |
-
model_id,
|
| 10 |
-
|
| 11 |
-
device_map="auto"
|
| 12 |
-
)
|
| 13 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
"content": [
|
| 21 |
-
{"type": "image", "image": image},
|
| 22 |
-
{"type": "text", "text": f"Instruction: {instruction}. Edit the image accordingly."},
|
| 23 |
-
],
|
| 24 |
-
}
|
| 25 |
-
]
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
image_inputs, video_inputs = process_vision_info(messages)
|
| 30 |
-
inputs = processor(
|
| 31 |
-
text=[text],
|
| 32 |
-
images=image_inputs,
|
| 33 |
-
videos=video_inputs,
|
| 34 |
-
padding=True,
|
| 35 |
-
return_tensors="pt"
|
| 36 |
-
).to("cuda")
|
| 37 |
-
|
| 38 |
-
# Generar (aqu铆 el modelo devuelve la imagen editada)
|
| 39 |
-
generated_ids = model.generate(**inputs, max_new_tokens=2048)
|
| 40 |
-
|
| 41 |
-
# Decodificar y procesar la salida (simplificado para el ejemplo)
|
| 42 |
-
# Nota: Qwen-VL suele devolver el resultado a trav茅s de una salida de pipeline
|
| 43 |
-
# espec铆fica definida en su model card.
|
| 44 |
-
return generated_ids
|
| 45 |
-
|
| 46 |
-
# Interfaz
|
| 47 |
-
demo = gr.Interface(
|
| 48 |
-
fn=edit_image,
|
| 49 |
-
inputs=[gr.Image(type="pil"), gr.Textbox(label="Instrucci贸n de Cosplay")],
|
| 50 |
-
outputs=gr.Image(),
|
| 51 |
-
title="Qwen-VL Cosplay Editor"
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
-
if __name__ == "__main__":
|
| 55 |
-
demo.launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
+
import spaces
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
+
from diffusers import StableDiffusionXLPipeline
|
| 5 |
|
| 6 |
+
# Usamos un modelo SDXL base que es extremadamente confiable y tiene todos sus archivos
|
| 7 |
+
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 8 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 9 |
+
model_id, torch_dtype=torch.float16, use_safetensors=True, variant="fp16"
|
| 10 |
+
).to("cuda")
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
@spaces.GPU
|
| 13 |
+
def generate(prompt):
|
| 14 |
+
# La clave es la consistencia, SDXL con un buen prompt es muy estable
|
| 15 |
+
image = pipe(prompt=prompt, num_inference_steps=25).images[0]
|
| 16 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
demo = gr.Interface(fn=generate, inputs="text", outputs="image")
|
| 19 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|