Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,91 +1,19 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
@st.cache_resource
|
| 6 |
-
def load_model(
|
| 7 |
-
|
| 8 |
-
return pipeline('text-generation', model='gpt2')
|
| 9 |
-
elif model_type == 'translation_en_to_fr':
|
| 10 |
-
return pipeline('translation_en_to_fr')
|
| 11 |
-
elif model_type == 'translation_en_to_ar':
|
| 12 |
-
return pipeline('translation_en_to_ar')
|
| 13 |
-
elif model_type == 'translation_en_to_en':
|
| 14 |
-
return pipeline('text-generation', model='gpt2')
|
| 15 |
|
| 16 |
-
|
| 17 |
-
generator = load_model('gpt2')
|
| 18 |
-
translator_en_fr = load_model('translation_en_to_fr')
|
| 19 |
-
translator_en_ar = load_model('translation_en_to_ar')
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
st.title("
|
| 23 |
-
st.write("
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# Botón para procesar el texto
|
| 32 |
-
if st.button("Procesar texto"):
|
| 33 |
-
if technical_text and experiment_text:
|
| 34 |
-
# Reescribir el texto técnico en un lenguaje accesible
|
| 35 |
-
with st.spinner("Reescribiendo texto técnico..."):
|
| 36 |
-
rewritten_text = generator(technical_text, do_sample=True, min_length=50, max_length=100)[0]['generated_text']
|
| 37 |
-
|
| 38 |
-
# Traducir a inglés, árabe y francés
|
| 39 |
-
with st.spinner("Traduciendo a inglés, árabe y francés..."):
|
| 40 |
-
translated_en = generator(technical_text, do_sample=True, min_length=50, max_length=100)[0]['generated_text'] # Traducción a inglés
|
| 41 |
-
translated_fr = translator_en_fr(technical_text)[0]['translation_text'] # Traducción a francés
|
| 42 |
-
translated_ar = translator_en_ar(technical_text)[0]['translation_text'] # Traducción a árabe
|
| 43 |
-
|
| 44 |
-
# Identificar el tema principal (simulando con generación de texto)
|
| 45 |
-
with st.spinner("Identificando el tema principal..."):
|
| 46 |
-
main_topic = generator(f"Identifica el tema principal: {technical_text}", do_sample=False, max_length=50)[0]['generated_text']
|
| 47 |
-
|
| 48 |
-
# Identificar el tono (simulando también)
|
| 49 |
-
with st.spinner("Identificando el tono del texto..."):
|
| 50 |
-
tone = generator(f"¿Cuál es el tono de este texto?: {technical_text}", do_sample=False, max_length=50)[0]['generated_text']
|
| 51 |
-
|
| 52 |
-
# Inferir conclusiones del experimento para un niño de 10 años
|
| 53 |
-
with st.spinner("Generando conclusiones accesibles..."):
|
| 54 |
-
conclusion = generator(f"Explica esto a un niño de 10 años: {experiment_text}", do_sample=True, min_length=50, max_length=100)[0]['generated_text']
|
| 55 |
-
|
| 56 |
-
# Formatear respuestas para enviar al web service
|
| 57 |
-
response = {
|
| 58 |
-
"rewritten_text": rewritten_text,
|
| 59 |
-
"translations": {
|
| 60 |
-
"english": translated_en,
|
| 61 |
-
"french": translated_fr,
|
| 62 |
-
"arabic": translated_ar
|
| 63 |
-
},
|
| 64 |
-
"main_topic": main_topic,
|
| 65 |
-
"tone": tone,
|
| 66 |
-
"conclusions": conclusion
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
# Mostrar los resultados
|
| 70 |
-
st.subheader("Texto reescrito:")
|
| 71 |
-
st.write(rewritten_text)
|
| 72 |
-
|
| 73 |
-
st.subheader("Traducciones:")
|
| 74 |
-
st.write("Inglés: ", translated_en)
|
| 75 |
-
st.write("Francés: ", translated_fr)
|
| 76 |
-
st.write("Árabe: ", translated_ar)
|
| 77 |
-
|
| 78 |
-
st.subheader("Tema principal:")
|
| 79 |
-
st.write(main_topic)
|
| 80 |
-
|
| 81 |
-
st.subheader("Tono:")
|
| 82 |
-
st.write(tone)
|
| 83 |
-
|
| 84 |
-
st.subheader("Conclusiones explicadas a un niño de 10 años:")
|
| 85 |
-
st.write(conclusion)
|
| 86 |
-
|
| 87 |
-
st.subheader("Formato para enviar al web service:")
|
| 88 |
-
st.json(response)
|
| 89 |
-
|
| 90 |
-
else:
|
| 91 |
-
st.error("Por favor, introduce ambos textos antes de generar las respuestas.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Inicializar el modelo generador de texto
|
| 5 |
+
@st.cache_resource # Esto cachea el modelo para no cargarlo repetidamente
|
| 6 |
+
def load_model():
|
| 7 |
+
return pipeline('text-generation', model='gpt2') # Cambia el modelo a gpt2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
generator = load_model()
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Crear la interfaz de usuario
|
| 12 |
+
st.title("Generador de texto GPT-2") # Actualiza el título para reflejar el nuevo modelo
|
| 13 |
+
st.write("Introduce dos textos para que el modelo los continúe:")
|
| 14 |
|
| 15 |
+
# Campo de entrada para el primer prompt
|
| 16 |
+
user_input_1 = st.text_input("Escribe el primer prompt aquí:", "")
|
| 17 |
|
| 18 |
+
# Campo de entrada para el segundo prompt
|
| 19 |
+
user_input_2 = st.text_input("Escribe el segundo prompt aquí:", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|