Spaces:
Sleeping
Sleeping
Download app.py from Prxjota/DiffusersTransformers: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/Prxjota/DiffusersTransformers/resolve/main/app.py
- Command line
-
hf download hf://spaces/Prxjota/DiffusersTransformers/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Prxjota/DiffusersTransformers/resolve/main/app.py
1.67 kB
| import gradio as gr | |
| from transformers import pipeline | |
| from diffusers import StableDiffusionPipeline | |
| import torch | |
| # Cargar modelo de resumen | |
| summarizer = pipeline("summarization", model="t5-small") | |
| # Cargar modelo de difusión | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| diffuser = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") | |
| diffuser = diffuser.to(device) | |
| # Funciones | |
| def resumir(texto): | |
| resumen = summarizer(texto, max_length=50, min_length=25, do_sample=False) | |
| return resumen[0]["summary_text"] | |
| def generar_imagen(prompt): | |
| imagen = diffuser(prompt).images[0] | |
| return imagen | |
| # Interfaz mejorada | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🧠✍️ Transformers y 🎨 Diffusers") | |
| with gr.Tab("Resumidor de texto"): | |
| gr.Markdown("Introduce un texto largo para resumirlo con un modelo Transformer.") | |
| texto_input = gr.Textbox(label="Texto de entrada", lines=5, placeholder="Escribe aquí tu texto...") | |
| resumen_output = gr.Textbox(label="Resumen") | |
| resumir_btn = gr.Button("Resumir") | |
| resumir_btn.click(resumir, inputs=texto_input, outputs=resumen_output) | |
| with gr.Tab("Generador de imágenes"): | |
| gr.Markdown("Introduce una descripción en inglés para generar una imagen con Diffusers.") | |
| prompt_input = gr.Textbox(label="Prompt (en inglés)", placeholder="Ej: A fantasy landscape with dragons") | |
| imagen_output = gr.Image(label="Imagen generada") | |
| generar_btn = gr.Button("Generar imagen") | |
| generar_btn.click(generar_imagen, inputs=prompt_input, outputs=imagen_output) | |
| demo.launch() | |