Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,43 @@
|
|
1 |
-
|
|
|
|
|
2 |
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
)
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
f"<|user|>\n{prompt}<|end|>\n<|assistant|>",
|
20 |
-
max_tokens=256, # Generate up to 256 tokens
|
21 |
-
stop=["<|end|>"],
|
22 |
-
echo=True, # Whether to echo the prompt
|
23 |
-
)
|
24 |
-
|
25 |
-
return (output['choices'][0]['text'])
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
|
|
|
|
30 |
|
31 |
|
32 |
# Create a Gradio interface
|
33 |
iface = gr.Interface(
|
34 |
-
fn=
|
35 |
inputs=gr.Textbox(lines=5, placeholder="Enter your prompt here..."),
|
36 |
outputs=gr.Textbox()
|
37 |
)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
4 |
|
5 |
+
torch.random.manual_seed(0)
|
6 |
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
8 |
+
"microsoft/Phi-3-mini-4k-instruct",
|
9 |
+
device_map="cuda",
|
10 |
+
torch_dtype="auto",
|
11 |
+
trust_remote_code=True,
|
12 |
+
)
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
14 |
+
|
15 |
+
messages = [
|
16 |
+
{"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
|
17 |
+
{"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
|
18 |
+
{"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
|
19 |
+
]
|
20 |
+
|
21 |
+
proc_pipe = pipeline(
|
22 |
+
"text-generation",
|
23 |
+
model=model,
|
24 |
+
tokenizer=tokenizer,
|
25 |
)
|
26 |
|
27 |
+
generation_args = {
|
28 |
+
"max_new_tokens": 500,
|
29 |
+
"return_full_text": False,
|
30 |
+
"temperature": 0.0,
|
31 |
+
"do_sample": False,
|
32 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
output = pipe(messages, **generation_args)
|
35 |
+
print(output[0]['generated_text'])
|
36 |
|
37 |
|
38 |
# Create a Gradio interface
|
39 |
iface = gr.Interface(
|
40 |
+
fn=proc_pipe,
|
41 |
inputs=gr.Textbox(lines=5, placeholder="Enter your prompt here..."),
|
42 |
outputs=gr.Textbox()
|
43 |
)
|