Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
from diffusers import StableDiffusionPipeline
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
# Cargar modelo para generar im谩genes desde texto
|
| 10 |
-
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
|
| 11 |
-
pipe.to("cuda" if torch.cuda.is_available() else "cpu") # Usar GPU si est谩 disponible
|
| 12 |
-
|
| 13 |
-
# Funci贸n para procesar imagen o texto
|
| 14 |
-
def process_input(image, description):
|
| 15 |
-
if image is not None: # Si el usuario sube una imagen
|
| 16 |
-
results = classifier(image)
|
| 17 |
-
return results[0]["label"], None # Devuelve la raza detectada
|
| 18 |
-
elif description: # Si el usuario escribe un texto
|
| 19 |
-
image = pipe(description).images[0]
|
| 20 |
-
return None, image # Devuelve la imagen generada
|
| 21 |
-
return "Por favor, sube una imagen o escribe una descripci贸n", None
|
| 22 |
-
|
| 23 |
-
# Interfaz de usuario con Gradio
|
| 24 |
-
iface = gr.Interface(
|
| 25 |
-
fn=process_input,
|
| 26 |
-
inputs=[gr.Image(type="pil"), gr.Textbox(label="Describe un gato o perro")],
|
| 27 |
-
outputs=[gr.Textbox(label="Predicci贸n"), gr.Image(label="Imagen generada")],
|
| 28 |
-
title="Detector y Generador de Razas de Gatos y Perros",
|
| 29 |
-
description="Sube una imagen para conocer la raza o escribe una descripci贸n para generar una imagen."
|
| 30 |
-
)
|
| 31 |
|
|
|
|
| 32 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def hello(name):
|
| 4 |
+
return f"Hola, {name}! Bienvenido a Hugging Face Spaces."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
iface = gr.Interface(fn=hello, inputs="text", outputs="text")
|
| 7 |
iface.launch()
|