|
import streamlit as st |
|
import random |
|
from transformers import pipeline |
|
|
|
|
|
st.set_page_config( |
|
page_title="¿No sabes qué decir? Te ayudamos", |
|
page_icon="💡", |
|
layout="centered" |
|
) |
|
|
|
|
|
st.markdown( |
|
""" |
|
<style> |
|
body { |
|
background-color: #fefaf4; |
|
} |
|
.title { |
|
font-size: 38px; |
|
font-weight: bold; |
|
text-align: center; |
|
color: #a3b18a; |
|
margin-bottom: 10px; |
|
} |
|
.subtitle { |
|
font-size: 18px; |
|
text-align: center; |
|
color: #588157; |
|
} |
|
.footer { |
|
text-align: center; |
|
font-size: 12px; |
|
margin-top: 30px; |
|
color: #8d99ae; |
|
} |
|
.stButton>button { |
|
background-color: #ffdab9; |
|
color: #3d405b; |
|
font-size: 16px; |
|
} |
|
</style> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
|
|
|
|
conectores = { |
|
"Explicación": ["porque", "ya que", "puesto que", "dado que"], |
|
"Contraste": ["sin embargo", "aunque", "no obstante", "a pesar de"], |
|
"Adición": ["además", "asimismo", "igualmente", "por otra parte"], |
|
"Causalidad negativa": ["pero", "sin embargo", "aunque"] |
|
} |
|
|
|
|
|
def agregar_conector_automatico(texto_usuario): |
|
categoria = random.choice(list(conectores.keys())) |
|
conector = random.choice(conectores[categoria]) |
|
|
|
if not texto_usuario.strip().endswith(tuple(conector for sublist in conectores.values() for conector in sublist)): |
|
texto_usuario += f" {conector}" |
|
return texto_usuario |
|
|
|
|
|
@st.cache_resource |
|
def load_model(): |
|
return pipeline("text-generation", model="datificate/gpt2-small-spanish") |
|
|
|
generator = load_model() |
|
|
|
|
|
st.markdown('<p class="title">¿No sabes qué decir? 💡</p>', unsafe_allow_html=True) |
|
st.markdown('<p class="subtitle">¡Te ayudamos a completar tus ideas con inteligencia artificial!</p>', unsafe_allow_html=True) |
|
|
|
|
|
st.subheader("📝 Escribe tu idea:") |
|
prompt = st.text_area("Completa tu idea:", placeholder="Ejemplo: Me gustaría escribir una carta a...") |
|
|
|
|
|
if st.button("✨ Generar Texto ✨"): |
|
if not prompt.strip(): |
|
st.warning("⚠️ Por favor, ingresa un texto válido.") |
|
else: |
|
with st.spinner("⏳ Generando texto..."): |
|
|
|
prompt_con_conector = agregar_conector_automatico(prompt) |
|
result = generator( |
|
prompt_con_conector, |
|
max_length=35, |
|
temperature=0.1, |
|
top_p=0.7, |
|
top_k=10, |
|
repetition_penalty=1.5, |
|
num_return_sequences=1, |
|
eos_token_id=50256, |
|
do_sample=False |
|
) |
|
response = result[0]["generated_text"] |
|
st.subheader("🖋️ Texto Generado:") |
|
st.success(response) |
|
|
|
|
|
st.markdown('<p class="footer">Grupo 7 - Procesamiento de datos con AI - Especialización de Inteligencia Artificial UAO</p>', unsafe_allow_html=True) |