|
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"]
|
|
}
|
|
|
|
|
|
def agregar_conector_automatico(texto_usuario):
|
|
categoria = random.choice(list(conectores.keys()))
|
|
conector = random.choice(conectores[categoria])
|
|
return f"{texto_usuario} {conector}"
|
|
|
|
|
|
@st.cache_resource
|
|
def load_model():
|
|
return pipeline("text-generation", model="PlanTL-GOB-ES/gpt2-base-bne")
|
|
|
|
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_new_tokens=25,
|
|
temperature=0.3,
|
|
top_p=0.8,
|
|
top_k=20,
|
|
repetition_penalty=1.2,
|
|
num_return_sequences=1
|
|
)
|
|
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) |