Ayeshanoor101
commited on
Commit
•
7fa6da1
1
Parent(s):
4d99a43
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
import torch
|
5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
6 |
+
|
7 |
+
torch.random.manual_seed(0)
|
8 |
+
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
10 |
+
"microsoft/Phi-3-mini-128k-instruct",
|
11 |
+
device_map="cuda",
|
12 |
+
torch_dtype="auto",
|
13 |
+
trust_remote_code=True,
|
14 |
+
)
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct")
|
16 |
+
|
17 |
+
pipe = pipeline(
|
18 |
+
"text-generation",
|
19 |
+
model=model,
|
20 |
+
tokenizer=tokenizer,
|
21 |
+
)
|
22 |
+
|
23 |
+
generation_args = {
|
24 |
+
"max_new_tokens": 500,
|
25 |
+
"return_full_text": False,
|
26 |
+
"temperature": 0.0,
|
27 |
+
"do_sample": False,
|
28 |
+
}
|
29 |
+
|
30 |
+
def chat(message, history):
|
31 |
+
messages = [
|
32 |
+
{"role": "user", "content": "Hi"},
|
33 |
+
{"role": "assistant", "content": "Hello.. How may I help you?"},
|
34 |
+
{"role": "user", "content": message},
|
35 |
+
]
|
36 |
+
output = pipe(messages, **generation_args)
|
37 |
+
print(output[0]['generated_text'])
|
38 |
+
return output[0]['generated_text']
|
39 |
+
|
40 |
+
demo = gr.ChatInterface(chat).queue()
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
demo.launch()
|