Finalización codigo
Browse files
README.md
CHANGED
|
@@ -5,7 +5,7 @@ colorFrom: red
|
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.25.2
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
short_description: prueba
|
|
|
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.25.2
|
| 8 |
+
app_file: app3.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
short_description: prueba
|
app.py
CHANGED
|
@@ -1,7 +1,18 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Mamahuevo " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
clasificador = pipeline("sentiment-analysis", model="pysentimiento/robertuito-sentiment-analysis")
|
|
|
|
| 5 |
|
| 6 |
+
def puntuacion_sentimientos (texto):
|
| 7 |
+
resultado = clasificador (texto)
|
| 8 |
+
print (resultado)
|
| 9 |
+
etiqueta = resultado[0]["label"]
|
| 10 |
+
if(etiqueta == "POS" ):
|
| 11 |
+
respuesta = "Tu frase es muy positiva"
|
| 12 |
+
elif etiqueta == "NEG":
|
| 13 |
+
respuesta = "Tu frase es muy negativa"
|
| 14 |
+
else:
|
| 15 |
+
respuesta = "ni fu ni fa"
|
| 16 |
+
return respuesta
|
| 17 |
+
demo = gr.Interface(fn=puntuacion_sentimientos, inputs="text", outputs="text")
|
| 18 |
+
demo. launch ()
|
app2.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
pipe = pipeline("text-classification", model="TheBritishLibrary/bl-books-genre")
|
| 5 |
+
|
| 6 |
+
def puntuacion_sentimientos (texto):
|
| 7 |
+
resultado = pipe (texto)
|
| 8 |
+
print (resultado)
|
| 9 |
+
etiqueta = resultado[0]["label"]
|
| 10 |
+
print(texto+': '+etiqueta)
|
| 11 |
+
return etiqueta
|
| 12 |
+
demo = gr.Interface(fn=puntuacion_sentimientos, inputs="text", outputs="text")
|
| 13 |
+
demo. launch ()
|
app3.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Carga del modelo de reescritura en español
|
| 7 |
+
text2text = pipeline("text2text-generation", model="mrm8488/t5-base-finetuned-summarize-news")
|
| 8 |
+
|
| 9 |
+
# Configuración de dispositivo para Stable Diffusion
|
| 10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
diffusion = StableDiffusionPipeline.from_pretrained(
|
| 12 |
+
"stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
| 13 |
+
).to(device)
|
| 14 |
+
|
| 15 |
+
# Función principal
|
| 16 |
+
def generate(text):
|
| 17 |
+
# Pedimos al modelo que genere una frase más visual
|
| 18 |
+
prompt = f"Mejora el siguiente texto en castellano sin repetirmelo: {text}"
|
| 19 |
+
improved = text2text(prompt, max_length=60, do_sample=True)[0]["generated_text"]
|
| 20 |
+
|
| 21 |
+
# Generamos imagen con la frase mejorada
|
| 22 |
+
image = diffusion(improved).images[0]
|
| 23 |
+
return improved, image
|
| 24 |
+
|
| 25 |
+
# Interfaz Gradio
|
| 26 |
+
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 27 |
+
gr.Markdown("# 🎨 Generador de Imágenes desde Texto en Español")
|
| 28 |
+
with gr.Row():
|
| 29 |
+
with gr.Column():
|
| 30 |
+
inp = gr.Textbox(label="Introduce una descripción breve", placeholder="Ej: Persona mayor sentada en un banco")
|
| 31 |
+
btn = gr.Button("Generar imagen")
|
| 32 |
+
with gr.Column():
|
| 33 |
+
out_text = gr.Textbox(label="Texto mejorado para la imagen")
|
| 34 |
+
out_img = gr.Image(label="Imagen generada")
|
| 35 |
+
|
| 36 |
+
btn.click(fn=generate, inputs=inp, outputs=[out_text, out_img])
|
| 37 |
+
|
| 38 |
+
demo.launch()
|
prueba.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
print(torch.cuda.is_available()) # Debe devolver: True
|
| 3 |
+
print(torch.cuda.get_device_name(0)) # Debe mostrar: tu GPU (ej. RTX 2060)
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==5.20.0
|
| 2 |
+
transformers==4.49.0
|
| 3 |
+
torch==2.6.0
|
| 4 |
+
gradio==5.20.0
|
| 5 |
+
diffusers==0.32.2
|
| 6 |
+
accelerate==1.5.2
|
| 7 |
+
pydantic==2.10.6
|