| import os | |
| import gradio as gr | |
| from huggingface_hub import login | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| login(os.environ["HF_TOKEN"]) | |
| model_id = "jimy26/Sherlock_Model" | |
| tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=True) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| device_map="auto", | |
| torch_dtype="auto", | |
| use_auth_token=True | |
| ) | |
| def chat(prompt): | |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=150, temperature=0.7, top_p=0.9) | |
| return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| gr.Interface( | |
| fn=chat, | |
| inputs=gr.Textbox(lines=3, placeholder="Ask Sherlock Holmes something..."), | |
| outputs="text", | |
| title="🕵️ Chat with Sherlock Holmes", | |
| description="A character-based chatbot fine-tuned to act like Sherlock Holmes." | |
| ).launch() | |