Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
client = InferenceClient(
|
5 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
@@ -15,20 +16,26 @@ def format_prompt(message, history):
|
|
15 |
return prompt
|
16 |
|
17 |
def generate(
|
18 |
-
prompt, history, system_prompt, temperature=0.
|
19 |
):
|
20 |
temperature = float(temperature)
|
21 |
if temperature < 1e-2:
|
22 |
temperature = 1e-2
|
23 |
top_p = float(top_p)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
generate_kwargs = dict(
|
26 |
temperature=temperature,
|
27 |
max_new_tokens=max_new_tokens,
|
28 |
top_p=top_p,
|
|
|
29 |
repetition_penalty=repetition_penalty,
|
30 |
do_sample=True,
|
31 |
-
seed=
|
32 |
)
|
33 |
|
34 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
@@ -44,9 +51,17 @@ def generate(
|
|
44 |
additional_inputs=[
|
45 |
gr.Textbox(
|
46 |
label="System Prompt",
|
47 |
-
max_lines=1,
|
48 |
interactive=True,
|
49 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
gr.Slider(
|
51 |
label="Temperature",
|
52 |
value=0.9,
|
@@ -57,13 +72,13 @@ additional_inputs=[
|
|
57 |
info="Higher values produce more diverse outputs",
|
58 |
),
|
59 |
gr.Slider(
|
60 |
-
label="
|
61 |
-
value=
|
62 |
-
minimum=0,
|
63 |
-
maximum=
|
64 |
-
step=
|
65 |
interactive=True,
|
66 |
-
info="
|
67 |
),
|
68 |
gr.Slider(
|
69 |
label="Top-p (nucleus sampling)",
|
@@ -75,29 +90,41 @@ additional_inputs=[
|
|
75 |
info="Higher values sample more low-probability tokens",
|
76 |
),
|
77 |
gr.Slider(
|
78 |
-
label="
|
79 |
-
value=1
|
80 |
-
minimum=
|
81 |
-
maximum=
|
82 |
-
step=
|
83 |
interactive=True,
|
84 |
-
info="
|
85 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
]
|
87 |
|
88 |
-
examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
|
89 |
-
["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
|
90 |
-
["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
|
91 |
-
["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
|
92 |
-
["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
|
93 |
-
["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
|
94 |
]
|
95 |
|
96 |
gr.ChatInterface(
|
97 |
fn=generate,
|
98 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
99 |
additional_inputs=additional_inputs,
|
100 |
-
title="Mixtral
|
|
|
101 |
examples=examples,
|
102 |
concurrency_limit=20,
|
103 |
).launch(show_api=False)
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
+
import random
|
4 |
|
5 |
client = InferenceClient(
|
6 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
|
|
16 |
return prompt
|
17 |
|
18 |
def generate(
|
19 |
+
prompt, history, system_prompt, max_new_tokens=100, temperature=0.7, repetition_penalty=1.2, top_p=0.95, top_k=1, random_seed=False, manual_seed=42,
|
20 |
):
|
21 |
temperature = float(temperature)
|
22 |
if temperature < 1e-2:
|
23 |
temperature = 1e-2
|
24 |
top_p = float(top_p)
|
25 |
|
26 |
+
if random_seed:
|
27 |
+
seed = random.randint(1, 100000)
|
28 |
+
else:
|
29 |
+
seed = manual_seed
|
30 |
+
|
31 |
generate_kwargs = dict(
|
32 |
temperature=temperature,
|
33 |
max_new_tokens=max_new_tokens,
|
34 |
top_p=top_p,
|
35 |
+
top_k=top_k,
|
36 |
repetition_penalty=repetition_penalty,
|
37 |
do_sample=True,
|
38 |
+
seed=seed,
|
39 |
)
|
40 |
|
41 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
|
|
51 |
additional_inputs=[
|
52 |
gr.Textbox(
|
53 |
label="System Prompt",
|
|
|
54 |
interactive=True,
|
55 |
),
|
56 |
+
gr.Slider(
|
57 |
+
label="Max new tokens",
|
58 |
+
value=1000,
|
59 |
+
minimum=0,
|
60 |
+
maximum=32768,
|
61 |
+
step=64,
|
62 |
+
interactive=True,
|
63 |
+
info="The maximum numbers of new tokens, controls how long is the output",
|
64 |
+
),
|
65 |
gr.Slider(
|
66 |
label="Temperature",
|
67 |
value=0.9,
|
|
|
72 |
info="Higher values produce more diverse outputs",
|
73 |
),
|
74 |
gr.Slider(
|
75 |
+
label="Repetition penalty",
|
76 |
+
value=1.2,
|
77 |
+
minimum=1.0,
|
78 |
+
maximum=2.0,
|
79 |
+
step=0.05,
|
80 |
interactive=True,
|
81 |
+
info="Penalize repeated tokens, making the AI repeat less itself",
|
82 |
),
|
83 |
gr.Slider(
|
84 |
label="Top-p (nucleus sampling)",
|
|
|
90 |
info="Higher values sample more low-probability tokens",
|
91 |
),
|
92 |
gr.Slider(
|
93 |
+
label="Top-k",
|
94 |
+
value=1,
|
95 |
+
minimum=0,
|
96 |
+
maximum=100,
|
97 |
+
step=1,
|
98 |
interactive=True,
|
99 |
+
info="Higher k means more diverse outputs by considering a range of tokens",
|
100 |
+
),
|
101 |
+
gr.Checkbox(
|
102 |
+
label="Use Random Seed",
|
103 |
+
value=False,
|
104 |
+
info="Use a random starting point to initiate the generation process instead of the manual one"
|
105 |
+
),
|
106 |
+
gr.Number(
|
107 |
+
label="Manual Seed",
|
108 |
+
value=42,
|
109 |
+
minimum=1,
|
110 |
+
info="Use a manual starting point to initiate the generation process",
|
111 |
+
),
|
112 |
]
|
113 |
|
114 |
+
examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, None],
|
115 |
+
["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None, None],
|
116 |
+
["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None, None],
|
117 |
+
["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None, None],
|
118 |
+
["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None, None],
|
119 |
+
["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None, None],
|
120 |
]
|
121 |
|
122 |
gr.ChatInterface(
|
123 |
fn=generate,
|
124 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
125 |
additional_inputs=additional_inputs,
|
126 |
+
title="Mixtral 8x7b Instruct v0.1 Chatbot",
|
127 |
+
description="Chatbot space with costumizable options for model: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1 \nSpace made by [Nick088](https://linktr.ee/Nick088) \nIf you get an erorr, you putted a too much high Max_New_Tokens or your system prompt+prompt is too long, shorten up one of these",
|
128 |
examples=examples,
|
129 |
concurrency_limit=20,
|
130 |
).launch(show_api=False)
|