Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,27 +2,33 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
model_name = "polyglots/SinLlama_v01"
|
| 7 |
-
|
|
|
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
model_name,
|
| 10 |
torch_dtype=torch.float16,
|
| 11 |
device_map="auto"
|
| 12 |
)
|
| 13 |
|
| 14 |
-
def chat_with_sinllama(
|
| 15 |
-
inputs = tokenizer(
|
| 16 |
-
outputs = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
-
history.append((
|
| 19 |
return history, history
|
| 20 |
|
| 21 |
-
# Gradio
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
-
chatbot = gr.Chatbot()
|
| 24 |
-
msg = gr.Textbox(label="Type your
|
| 25 |
-
clear = gr.Button("Clear
|
| 26 |
|
| 27 |
msg.submit(chat_with_sinllama, [msg, chatbot], [chatbot, chatbot])
|
| 28 |
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Use LLaMA architecture explicitly
|
| 6 |
model_name = "polyglots/SinLlama_v01"
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
|
| 9 |
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
model_name,
|
| 11 |
torch_dtype=torch.float16,
|
| 12 |
device_map="auto"
|
| 13 |
)
|
| 14 |
|
| 15 |
+
def chat_with_sinllama(message, history=[]):
|
| 16 |
+
inputs = tokenizer(message, return_tensors="pt").to(model.device)
|
| 17 |
+
outputs = model.generate(
|
| 18 |
+
**inputs,
|
| 19 |
+
max_new_tokens=200,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
do_sample=True
|
| 22 |
+
)
|
| 23 |
reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 24 |
+
history.append((message, reply))
|
| 25 |
return history, history
|
| 26 |
|
| 27 |
+
# Gradio app
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
+
chatbot = gr.Chatbot(label="SinLlama (Sinhala Chatbot)")
|
| 30 |
+
msg = gr.Textbox(label="Type your message in Sinhala")
|
| 31 |
+
clear = gr.Button("Clear")
|
| 32 |
|
| 33 |
msg.submit(chat_with_sinllama, [msg, chatbot], [chatbot, chatbot])
|
| 34 |
clear.click(lambda: None, None, chatbot, queue=False)
|