Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
|
4 |
model_name = "anasmkh/customized_llama3.1_8b"
|
|
|
5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
|
7 |
|
@@ -11,20 +12,22 @@ generator = pipeline(
|
|
11 |
tokenizer=tokenizer,
|
12 |
max_new_tokens=64,
|
13 |
temperature=1.5,
|
14 |
-
min_p=0.1
|
15 |
)
|
16 |
|
17 |
-
def
|
18 |
-
|
19 |
-
{"role": "user", "content":
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
demo.launch()
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
|
4 |
model_name = "anasmkh/customized_llama3.1_8b"
|
5 |
+
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
|
8 |
|
|
|
12 |
tokenizer=tokenizer,
|
13 |
max_new_tokens=64,
|
14 |
temperature=1.5,
|
15 |
+
min_p=0.1,
|
16 |
)
|
17 |
|
18 |
+
def chat(message, history):
|
19 |
+
history = history or []
|
20 |
+
history.append({"role": "user", "content": message})
|
21 |
+
response = generator(history)[-1]["generated_text"]
|
22 |
+
history.append({"role": "assistant", "content": response})
|
23 |
+
return history
|
24 |
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
chatbot = gr.Chatbot()
|
27 |
+
message = gr.Textbox()
|
28 |
+
clear = gr.ClearButton([message, chatbot])
|
29 |
+
|
30 |
+
message.submit(chat, [message, chatbot], chatbot)
|
31 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
32 |
|
33 |
demo.launch()
|