Spaces:
Sleeping
Sleeping
psurmreqmer commited on
Commit 路
e110934
1
Parent(s): 9c8f4c2
- app.py +20 -22
- app_prueba.py +28 -0
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,28 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
respuesta = "Tu frase muy negativa"
|
| 14 |
-
else:
|
| 15 |
-
respuesta = "ni fu ni fa"
|
| 16 |
-
return respuesta
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
-
fn=
|
| 20 |
-
inputs=gr.
|
| 21 |
outputs=gr.Textbox(),
|
| 22 |
-
title="
|
| 23 |
-
description="
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
)
|
| 28 |
-
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
+
# Cargar modelo
|
| 6 |
+
model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 7 |
+
processor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 9 |
|
| 10 |
+
def describir(imagen):
|
| 11 |
+
if imagen is None:
|
| 12 |
+
return "Sube una imagen"
|
| 13 |
+
img = Image.fromarray(imagen)
|
| 14 |
+
inputs = processor(images=img, return_tensors="pt")
|
| 15 |
+
ids = model.generate(**inputs, max_length=40)
|
| 16 |
+
return tokenizer.decode(ids[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
+
fn=describir,
|
| 20 |
+
inputs=gr.Image(type="numpy"),
|
| 21 |
outputs=gr.Textbox(),
|
| 22 |
+
title="Descripci贸n de Im谩genes",
|
| 23 |
+
description="Sube una imagen y se generar谩 una descripci贸n para accesibilidad."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|
|
|
|
|
|
app_prueba.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 muy positiva"
|
| 12 |
+
elif etiqueta == "NEG":
|
| 13 |
+
respuesta = "Tu frase muy negativa"
|
| 14 |
+
else:
|
| 15 |
+
respuesta = "ni fu ni fa"
|
| 16 |
+
return respuesta
|
| 17 |
+
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=puntuacion_sentimientos,
|
| 20 |
+
inputs=gr.Textbox(),
|
| 21 |
+
outputs=gr.Textbox(),
|
| 22 |
+
title="Ejemplo Sentimientos de las frases",
|
| 23 |
+
description="Esta es nuestra interfaz para probar <strong>modelos de UA</strong>",
|
| 24 |
+
article="En este modelo, escribe una frase y pulsa en **Comprobar** para ver si tiene sentimientos positivos, negativos o neutros",
|
| 25 |
+
submit_btn="comprobar",
|
| 26 |
+
fill_width=True
|
| 27 |
+
)
|
| 28 |
+
demo.launch(theme=gr.themes.Soft())
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
gradio
|
| 2 |
transformers==4.49.0
|
| 3 |
-
torch==2.6.0
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
transformers==4.49.0
|
| 3 |
+
torch==2.6.0
|
| 4 |
+
Pillow
|