Spaces:
Paused
Paused
File size: 1,053 Bytes
7971d45 1a5e155 7971d45 3f0376d 7971d45 7886f0d 1a5e155 7886f0d 1a5e155 7886f0d 1a5e155 3f0376d 1a5e155 7886f0d 1a5e155 7886f0d 1a5e155 7886f0d 1a5e155 |
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 31 32 33 |
import os
from huggingface_hub import login
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import gradio as gr
import torch
# Autenticar usando el token almacenado como secreto
hf_token = os.getenv("HF_API_TOKEN")
login(hf_token)
# Cargar el modelo y el tokenizador
model_name = "mrm8488/t5-base-finetuned-spanish"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
def generate_text(input_text):
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
outputs = model.generate(**inputs, max_length=200, num_beams=4, early_stopping=True)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return generated_text
# Crear la interfaz con Gradio
iface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="Generador de Texto en Español",
description="Genera texto en español utilizando un modelo de lenguaje preentrenado."
)
iface.launch()
|