Aitheras commited on
Commit ·
2b90e82
1
Parent(s): 3d462bb
add app
Browse files- .gitignore +1 -0
- app.py +32 -0
- requirements.txt +5 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
venv/
|
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-3-270m")
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-3-270m")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def predict(message, history):
|
| 13 |
+
chat_history = []
|
| 14 |
+
for user, bot in history:
|
| 15 |
+
chat_history.append(user)
|
| 16 |
+
chat_history.append(bot)
|
| 17 |
+
chat_history.append(message)
|
| 18 |
+
|
| 19 |
+
input_ids = tokenizer(chat_history, padding="longest", return_tensors="pt")['input_ids']
|
| 20 |
+
chat_history_ids = model.generate(
|
| 21 |
+
input_ids,
|
| 22 |
+
max_length=512,
|
| 23 |
+
num_return_sequences=1, # Number of response sequences to generate
|
| 24 |
+
early_stopping=False,
|
| 25 |
+
do_sample=True,
|
| 26 |
+
)
|
| 27 |
+
response = tokenizer.decode(chat_history_ids[-1], skip_special_tokens=True)
|
| 28 |
+
yield response
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
if __name__=="__main__":
|
| 32 |
+
gr.ChatInterface(predict).queue().launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
# -i https://download.pytorch.org/whl/cpu
|
| 4 |
+
torch
|
| 5 |
+
sentencepiece
|