Uhhy commited on
Commit
3275443
verified
1 Parent(s): 219a3c8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import torch
4
+ from diffusers import StableDiffusionPipeline
5
+
6
+ # Cargar el modelo Stable Diffusion
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ model_id = "CompVis/stable-diffusion-v1-4" # Usa el modelo adecuado seg煤n la versi贸n disponible
9
+ pipe = StableDiffusionPipeline.from_pretrained(model_id).to(device)
10
+
11
+ def cartoonize_image(image):
12
+ prompt = "A Pixar-style cartoon character"
13
+
14
+ # Preprocesar imagen
15
+ image = image.convert("RGB")
16
+ image = image.resize((512, 512)) # Ajusta el tama帽o seg煤n sea necesario
17
+
18
+ # Generar imagen con Stable Diffusion
19
+ with torch.no_grad():
20
+ result = pipe(prompt=prompt, init_image=image, strength=0.75).images[0]
21
+
22
+ return result
23
+
24
+ # Configuraci贸n de la interfaz de Gradio
25
+ def main():
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("## Conversi贸n de Imagen a Caricatura Estilo Pixar")
28
+ with gr.Row():
29
+ with gr.Column():
30
+ input_image = gr.Image(type="pil", label="Sube tu imagen")
31
+ output_image = gr.Image(type="pil", label="Imagen Caricaturizada")
32
+
33
+ input_image.change(
34
+ fn=cartoonize_image,
35
+ inputs=input_image,
36
+ outputs=output_image
37
+ )
38
+
39
+ demo.launch()
40
+
41
+ if __name__ == "__main__":
42
+ main()