File size: 1,005 Bytes
6c036c1
aab52b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Cargar el modelo y tokenizador
model_name = "BSC-LT/salamandra-7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)

# Función de generación de texto
def generate_response(prompt):
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(inputs.input_ids, max_length=200, do_sample=True, temperature=0.7)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Crear la interfaz en Gradio
with gr.Blocks() as demo:
    gr.Markdown("# 🧠 Chatbot ALIA - Prueba en Hugging Face")
    with gr.Row():
        input_text = gr.Textbox(label="Escribe tu texto aquí")
        output_text = gr.Textbox(label="Respuesta de ALIA")
    submit_button = gr.Button("Generar respuesta")
    submit_button.click(generate_response, inputs=input_text, outputs=output_text)

demo.launch()