Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,47 +6,44 @@ def load_model(model_name):
|
|
6 |
|
7 |
def generate(
|
8 |
model_name,
|
9 |
-
|
10 |
user_input,
|
11 |
temperature=0.4,
|
12 |
top_p=0.25,
|
13 |
top_k=7,
|
14 |
max_new_tokens=256,
|
|
|
15 |
):
|
16 |
pipe = load_model(model_name)
|
17 |
-
if
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
},
|
29 |
-
{"role": "user", "content": user_input},
|
30 |
-
]
|
31 |
-
|
32 |
prompt = pipe.tokenizer.apply_chat_template(message_template, tokenize=False, add_generation_prompt=True)
|
33 |
outputs = pipe(prompt, max_new_tokens=max_new_tokens, do_sample=True,
|
34 |
-
temperature=temperature, top_k=top_k, top_p=top_p, repetition_penalty=
|
35 |
return outputs[0]["generated_text"]
|
36 |
|
37 |
model_choices = ["Felladrin/Pythia-31M-Chat-v1", "Felladrin/Llama-160M-Chat-v1", "Felladrin/Smol-Llama-101M-Chat-v1", "Felladrin/TinyMistral-248M-SFT-v4"]
|
38 |
-
template_choices = ["System-User-Assistant", "User-Assistant"]
|
39 |
|
40 |
g = gr.Interface(
|
41 |
fn=generate,
|
42 |
inputs=[
|
43 |
gr.components.Dropdown(choices=model_choices, label="Model", value=model_choices[0], interactive=True),
|
44 |
-
gr.components.
|
45 |
-
gr.components.Textbox(lines=2, label="
|
46 |
gr.components.Slider(minimum=0, maximum=1, value=0.4, label="Temperature"),
|
47 |
gr.components.Slider(minimum=0, maximum=1, value=0.25, label="Top p"),
|
48 |
gr.components.Slider(minimum=0, maximum=100, step=1, value=7, label="Top k"),
|
49 |
-
gr.components.Slider(minimum=1, maximum=1024, step=1, value=256, label="Max tokens"),
|
|
|
50 |
],
|
51 |
outputs=[gr.Textbox(lines=10, label="Output")],
|
52 |
title="Chat with models fine-tuned by Felladrin",
|
|
|
6 |
|
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 |
max_new_tokens=256,
|
15 |
+
repetition_penalty=1.0,
|
16 |
):
|
17 |
pipe = load_model(model_name)
|
18 |
+
if model_name == "Felladrin/Pythia-31M-Chat-v1":
|
19 |
+
repetition_penalty=1.0016
|
20 |
+
message_template = [
|
21 |
+
{
|
22 |
+
"role": "system",
|
23 |
+
"content": system_input,
|
24 |
+
},
|
25 |
+
{"role": "user", "content": "Hello!"},
|
26 |
+
{"role": "assistant", "content": "Hi! How can I assist you today?"},
|
27 |
+
{"role": "user", "content": user_input},
|
28 |
+
]
|
|
|
|
|
|
|
|
|
29 |
prompt = pipe.tokenizer.apply_chat_template(message_template, tokenize=False, add_generation_prompt=True)
|
30 |
outputs = pipe(prompt, max_new_tokens=max_new_tokens, do_sample=True,
|
31 |
+
temperature=temperature, top_k=top_k, top_p=top_p, repetition_penalty=repetition_penalty)
|
32 |
return outputs[0]["generated_text"]
|
33 |
|
34 |
model_choices = ["Felladrin/Pythia-31M-Chat-v1", "Felladrin/Llama-160M-Chat-v1", "Felladrin/Smol-Llama-101M-Chat-v1", "Felladrin/TinyMistral-248M-SFT-v4"]
|
|
|
35 |
|
36 |
g = gr.Interface(
|
37 |
fn=generate,
|
38 |
inputs=[
|
39 |
gr.components.Dropdown(choices=model_choices, label="Model", value=model_choices[0], interactive=True),
|
40 |
+
gr.components.Textbox(lines=2, label="System Message", value="You are a highly knowledgeable and friendly chatbot equipped with extensive information across various domains. 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."),
|
41 |
+
gr.components.Textbox(lines=2, label="User Message", value="How many planets are in our solar system?"),
|
42 |
gr.components.Slider(minimum=0, maximum=1, value=0.4, label="Temperature"),
|
43 |
gr.components.Slider(minimum=0, maximum=1, value=0.25, label="Top p"),
|
44 |
gr.components.Slider(minimum=0, maximum=100, step=1, value=7, label="Top k"),
|
45 |
+
gr.components.Slider(minimum=1, maximum=1024, step=1, value=256, label="Max tokens"),
|
46 |
+
gr.components.Slider(minimum=1.0, maximum=2.0, step=0.001, value=1.0, label="Repetition Penalty"),
|
47 |
],
|
48 |
outputs=[gr.Textbox(lines=10, label="Output")],
|
49 |
title="Chat with models fine-tuned by Felladrin",
|