Spaces:
Runtime error
Runtime error
Download app.py from Rafael2137/Mi_chat_Bot: direct link, hf CLI and curl.
- Browser
- Download file 736 Bytes
-
https://huggingface.co/spaces/Rafael2137/Mi_chat_Bot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rafael2137/Mi_chat_Bot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rafael2137/Mi_chat_Bot/resolve/main/app.py
736 Bytes
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import torch | |
| model_name = "mistralai/Mistral-7B-Instruct-v0.2" # modelo gratuito | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| device_map="auto", | |
| torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32 | |
| ) | |
| def chat(message, history=[]): | |
| inputs = tokenizer(message, return_tensors="pt").to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=200) | |
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return response | |
| demo = gr.Interface( | |
| fn=chat, | |
| inputs=["text", "state"], | |
| outputs="text" | |
| ) | |
| demo.launch() | |