EnriqueVega1995 commited on
Commit
470582a
1 Parent(s): 77e3c31
Files changed (1) hide show
  1. app.py +12 -29
app.py CHANGED
@@ -1,36 +1,19 @@
1
- from diffusers import AutoPipelineForText2Image
2
  import gradio as gr
 
 
3
  import torch
4
 
5
- device = "cpu"
6
- if torch.cuda.is_available():
7
- device = "cuda:0"
8
- if torch.backends.mps.is_available():
9
- device = "mps"
10
 
11
- # Inicializar el pipeline de diffusers
12
- pipeline = AutoPipelineForText2Image.from_pretrained(
13
- "runwayml/stable-diffusion-v1-5",
14
- torch_dtype=torch.float16,
15
- use_safetensors=True
16
- ).to(device)
17
- pipeline.enable_model_cpu_offload()
18
 
19
- def generate_image(prompt):
20
- # Generar imagen basada en el prompt
21
- with torch.no_grad(): # Desactivar el cálculo de gradientes para la inferencia
22
- image = pipeline(prompt, num_inference_steps=25).images[0]
23
-
24
- return image
25
-
26
- # Interfaz de Gradio
27
- iface = gr.Interface(
28
- fn=generate_image,
29
- inputs=gr.Textbox(lines=2, placeholder="Introduce tu descripción aquí..."), # Modificado aquí
30
- outputs="image",
31
- title="Generador de Imágenes de Texto a Imagen",
32
- description="Este modelo genera imágenes basadas en descripciones de texto. Introduce una descripción y observa la imagen generada."
33
  )
34
-
35
  if __name__ == "__main__":
36
- iface.launch()
 
 
1
  import gradio as gr
2
+ from diffusers import DDPMPipeline
3
+ from transformers import pipeline
4
  import torch
5
 
6
+ pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
 
 
 
7
 
8
+ def predict(input_img):
9
+ predictions = pipeline(input_img)
10
+ return input_img, {p["label"]: p["score"] for p in predictions}
 
 
 
 
11
 
12
+ gradio_app = gr.Interface(
13
+ predict,
14
+ inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
15
+ outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
16
+ title="Hot Dog? Or Not?",
 
 
 
 
 
 
 
 
 
17
  )
 
18
  if __name__ == "__main__":
19
+ gradio_app.launch()