Spaces:
Runtime error
Runtime error
Download app.py from Rafael2137/Chat-Bot: direct link, hf CLI and curl.
- Browser
- Download file 861 Bytes
-
https://huggingface.co/spaces/Rafael2137/Chat-Bot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rafael2137/Chat-Bot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rafael2137/Chat-Bot/resolve/main/app.py
861 Bytes
| 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() | |