Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,26 +7,32 @@ def load_model(model_name):
|
|
7 |
def generate(
|
8 |
model_name,
|
9 |
system_input,
|
|
|
|
|
10 |
user_input,
|
11 |
-
temperature=0.4,
|
12 |
-
top_p=0.25,
|
13 |
-
top_k=7,
|
14 |
-
repetition_penalty=1.0,
|
15 |
-
max_new_tokens=256,
|
16 |
):
|
17 |
pipe = load_model(model_name)
|
|
|
18 |
message_template = [
|
19 |
-
{
|
20 |
-
|
21 |
-
|
22 |
-
},
|
23 |
-
{"role": "user", "content": "Hi!"},
|
24 |
-
{"role": "assistant", "content": "Hello there. How can I assist you today?"},
|
25 |
{"role": "user", "content": user_input},
|
26 |
]
|
|
|
27 |
prompt = pipe.tokenizer.apply_chat_template(message_template, tokenize=False, add_generation_prompt=True)
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
return outputs[0]["generated_text"]
|
31 |
|
32 |
model_choices = ["Felladrin/Llama-160M-Chat-v1", "Felladrin/Smol-Llama-101M-Chat-v1", "Felladrin/TinyMistral-248M-SFT-v4", "Felladrin/Pythia-31M-Chat-v1"]
|
@@ -36,12 +42,9 @@ g = gr.Interface(
|
|
36 |
inputs=[
|
37 |
gr.components.Dropdown(choices=model_choices, label="Model", value=model_choices[0], interactive=True),
|
38 |
gr.components.Textbox(lines=2, label="System Message", value="You are a highly knowledgeable and friendly assistant. Your goal is to understand and respond to user inquiries with accuracy and clarity. You're adept at providing detailed explanations, concise summaries, and insightful responses. Your interactions are always respectful, helpful, and focused on delivering the most relevant information to the user."),
|
|
|
|
|
39 |
gr.components.Textbox(lines=2, label="User Message", value="Tell me something curious about the Earth!"),
|
40 |
-
gr.components.Slider(minimum=0, maximum=1, value=0.4, label="Temperature"),
|
41 |
-
gr.components.Slider(minimum=0, maximum=1, value=0.25, label="Top p"),
|
42 |
-
gr.components.Slider(minimum=0, maximum=50, step=1, value=7, label="Top k"),
|
43 |
-
gr.components.Slider(minimum=1.0, maximum=1.5, step=0.001, value=1.0016, label="Repetition Penalty"),
|
44 |
-
gr.components.Slider(minimum=1, maximum=1024, step=1, value=256, label="Max tokens"),
|
45 |
],
|
46 |
outputs=[gr.Textbox(lines=10, label="Output")],
|
47 |
title="A place to try out text-generation models fine-tuned by Felladrin",
|
|
|
7 |
def generate(
|
8 |
model_name,
|
9 |
system_input,
|
10 |
+
user_initial_message,
|
11 |
+
assistant_initial_message,
|
12 |
user_input,
|
|
|
|
|
|
|
|
|
|
|
13 |
):
|
14 |
pipe = load_model(model_name)
|
15 |
+
|
16 |
message_template = [
|
17 |
+
{"role": "system", "content": system_input},
|
18 |
+
{"role": "user", "content": user_initial_message},
|
19 |
+
{"role": "assistant", "content": assistant_initial_message},
|
|
|
|
|
|
|
20 |
{"role": "user", "content": user_input},
|
21 |
]
|
22 |
+
|
23 |
prompt = pipe.tokenizer.apply_chat_template(message_template, tokenize=False, add_generation_prompt=True)
|
24 |
+
|
25 |
+
if model_name == "Felladrin/Pythia-31M-Chat-v1":
|
26 |
+
outputs = pipe(prompt, max_new_tokens=1024, do_sample=True, temperature=0.4, top_k=7, top_p=0.25, repetition_penalty=1.0016)
|
27 |
+
elif model_name == "Felladrin/Llama-160M-Chat-v1":
|
28 |
+
outputs = pipe(prompt, max_new_tokens=1024, penalty_alpha=0.5, top_k=5, repetition_penalty=1.01)
|
29 |
+
elif model_name == "Felladrin/TinyMistral-248M-SFT-v4":
|
30 |
+
outputs = pipe(prompt, max_new_tokens=1024, penalty_alpha=0.5, top_k=5, repetition_penalty=1.0)
|
31 |
+
elif model_name == "Felladrin/Smol-Llama-101M-Chat-v1":
|
32 |
+
outputs = pipe(prompt, max_new_tokens=1024, penalty_alpha=0.5, top_k=5, repetition_penalty=1.0, add_special_tokens=True)
|
33 |
+
else:
|
34 |
+
outputs = pipe(prompt, max_new_tokens=1024, do_sample=True, temperature=0.9, top_k=50, top_p=0.95, repetition_penalty=1.2)
|
35 |
+
|
36 |
return outputs[0]["generated_text"]
|
37 |
|
38 |
model_choices = ["Felladrin/Llama-160M-Chat-v1", "Felladrin/Smol-Llama-101M-Chat-v1", "Felladrin/TinyMistral-248M-SFT-v4", "Felladrin/Pythia-31M-Chat-v1"]
|
|
|
42 |
inputs=[
|
43 |
gr.components.Dropdown(choices=model_choices, label="Model", value=model_choices[0], interactive=True),
|
44 |
gr.components.Textbox(lines=2, label="System Message", value="You are a highly knowledgeable and friendly assistant. Your goal is to understand and respond to user inquiries with accuracy and clarity. You're adept at providing detailed explanations, concise summaries, and insightful responses. Your interactions are always respectful, helpful, and focused on delivering the most relevant information to the user."),
|
45 |
+
gr.components.Textbox(lines=2, label="User Initial Message", value="Hi!"),
|
46 |
+
gr.components.Textbox(lines=2, label="Assistant Initial Message", value="Hello there. How can I assist you today?"),
|
47 |
gr.components.Textbox(lines=2, label="User Message", value="Tell me something curious about the Earth!"),
|
|
|
|
|
|
|
|
|
|
|
48 |
],
|
49 |
outputs=[gr.Textbox(lines=10, label="Output")],
|
50 |
title="A place to try out text-generation models fine-tuned by Felladrin",
|