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()