Spaces:
Paused
Paused
import os | |
from huggingface_hub import login | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
import gradio as gr | |
# 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 = "DeepESP/gpt2-spanish" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
def chat_with_gpt2_spanish(input_text): | |
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512) | |
outputs = model.generate(**inputs, max_length=200, num_beams=4, early_stopping=True) | |
response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return response | |
# Crear la interfaz con Gradio | |
iface = gr.Interface( | |
fn=chat_with_gpt2_spanish, | |
inputs="text", | |
outputs="text", | |
title="Chat con GPT-2 en Español", | |
description="Interfaz simple para comunicarte con el modelo GPT-2 en español." | |
) | |
iface.launch() |