lazarusrolando commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
message,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
max_new_tokens=128,
|
| 13 |
-
|
| 14 |
-
|
| 15 |
)
|
| 16 |
|
| 17 |
-
return
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
demo = gr.Interface(
|
| 20 |
-
fn=
|
| 21 |
-
inputs=gr.Textbox(
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
title="OpenHusky"
|
| 24 |
)
|
| 25 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
MODEL_ID = "lazarus19/OpenHusky"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 8 |
+
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
MODEL_ID,
|
| 11 |
+
torch_dtype=torch.float32
|
| 12 |
)
|
| 13 |
|
| 14 |
+
def generate_response(message):
|
| 15 |
+
inputs = tokenizer(
|
| 16 |
message,
|
| 17 |
+
return_tensors="pt"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
outputs = model.generate(
|
| 21 |
+
**inputs,
|
| 22 |
max_new_tokens=128,
|
| 23 |
+
temperature=0.7,
|
| 24 |
+
do_sample=True
|
| 25 |
)
|
| 26 |
|
| 27 |
+
return tokenizer.decode(
|
| 28 |
+
outputs[0],
|
| 29 |
+
skip_special_tokens=True
|
| 30 |
+
)
|
| 31 |
|
| 32 |
demo = gr.Interface(
|
| 33 |
+
fn=generate_response,
|
| 34 |
+
inputs=gr.Textbox(
|
| 35 |
+
lines=3,
|
| 36 |
+
placeholder="Ask OpenHusky..."
|
| 37 |
+
),
|
| 38 |
+
outputs="text",
|
| 39 |
title="OpenHusky"
|
| 40 |
)
|
| 41 |
|