File size: 861 Bytes
9964b72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

# Modelo público y ligero
model_name = "google/gemma-2b"

# Cargar tokenizer y modelo
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Crear pipeline de generación de texto
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)

# Función para el chatbot
def chat(prompt):
    output = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
    return output[0]['generated_text']

# Interfaz Gradio
demo = gr.Interface(
    fn=chat,
    inputs=gr.Textbox(lines=2, placeholder="Escribe tu mensaje aquí..."),
    outputs=gr.Textbox(),
    title="Chatbot IA",
    description="Chatbot usando Gemma-2B, modelo público"
)

if __name__ == "__main__":
    demo.launch()