File size: 903 Bytes
3fcc817
592f63a
3fcc817
 
592f63a
 
 
3fcc817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st
import torch
from transformers import pipeline

# Verificar si PyTorch está disponible
st.write(f"PyTorch disponible: {torch.cuda.is_available()}")

# Título de la app
st.title("Generador de Texto con GPT-2")

# Inicializar el modelo de Hugging Face
st.write("Cargando modelo GPT-2...")
generator = pipeline("text-generation", model="gpt2")

# Input del usuario
prompt = st.text_area("Escribe un texto para que GPT-2 continúe:")

# Botón para generar texto
if st.button("Generar Texto"):
    if prompt.strip() == "":
        st.warning("Por favor, ingresa un texto válido.")
    else:
        with st.spinner("Generando texto..."):
            # Generar texto usando GPT-2
            output = generator(prompt, max_length=100, num_return_sequences=1)
        
        # Mostrar resultado
        st.subheader("Texto Generado:")
        st.write(output[0]["generated_text"])