Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import pytesseract
|
4 |
|
5 |
-
#
|
|
|
|
|
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained("sambanovasystems/SambaLingo-Arabic-Chat")
|
7 |
model = AutoModelForCausalLM.from_pretrained("sambanovasystems/SambaLingo-Arabic-Chat")
|
8 |
|
9 |
-
# Use a pipeline as a high-level helper
|
10 |
-
chat_model = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
11 |
-
|
12 |
# Chat function
|
13 |
def chat_fn(history, user_input):
|
14 |
conversation = {"history": history, "user": user_input}
|
15 |
-
response
|
16 |
-
|
|
|
|
|
17 |
history.append((user_input, conversation["bot"]))
|
18 |
return history, ""
|
19 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
3 |
import pytesseract
|
4 |
|
5 |
+
# Use a pipeline as a high-level helper
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
# Initialize tokenizer and model
|
9 |
tokenizer = AutoTokenizer.from_pretrained("sambanovasystems/SambaLingo-Arabic-Chat")
|
10 |
model = AutoModelForCausalLM.from_pretrained("sambanovasystems/SambaLingo-Arabic-Chat")
|
11 |
|
|
|
|
|
|
|
12 |
# Chat function
|
13 |
def chat_fn(history, user_input):
|
14 |
conversation = {"history": history, "user": user_input}
|
15 |
+
# Generate a response using the model
|
16 |
+
input_ids = tokenizer.encode(user_input, return_tensors="pt")
|
17 |
+
response = model.generate(input_ids=input_ids, max_length=50)
|
18 |
+
conversation["bot"] = tokenizer.decode(response[0], skip_special_tokens=True)
|
19 |
history.append((user_input, conversation["bot"]))
|
20 |
return history, ""
|
21 |
|