Update README.md
Browse files
README.md
CHANGED
|
@@ -10,3 +10,36 @@ base_model:
|
|
| 10 |
pipeline_tag: text-generation
|
| 11 |
---
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
pipeline_tag: text-generation
|
| 11 |
---
|
| 12 |
|
| 13 |
+
|
| 14 |
+
""" from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
model_path = ""
|
| 18 |
+
|
| 19 |
+
# Load the tokenizer and set the padding token to the eos_token.
|
| 20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 21 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 22 |
+
|
| 23 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 24 |
+
model_path,
|
| 25 |
+
torch_dtype=torch.float16,
|
| 26 |
+
device_map="auto"
|
| 27 |
+
).to("cuda")
|
| 28 |
+
|
| 29 |
+
def generate_response(user_input):
|
| 30 |
+
instruction = """You are chatbot proficient in Nepalese Language."""
|
| 31 |
+
|
| 32 |
+
messages = [
|
| 33 |
+
{"role": "system", "content": instruction},
|
| 34 |
+
{"role": "user", "content": user_input}
|
| 35 |
+
]
|
| 36 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 37 |
+
inputs = tokenizer(prompt, return_tensors='pt', padding=True, truncation=True).to("cuda")
|
| 38 |
+
outputs = model.generate(**inputs, max_new_tokens=500, num_return_sequences=1)
|
| 39 |
+
response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 40 |
+
return response_text.split("assistant")[1].strip()
|
| 41 |
+
|
| 42 |
+
user_query = "राणा शासनले नेपाल कसरी कब्जा गर्यो भनेर व्याख्या गर्न सक्नुहुन्छ?"
|
| 43 |
+
response = generate_response(user_query)
|
| 44 |
+
print("Chatbot:", response) """
|
| 45 |
+
|