Spaces:
Sleeping
Sleeping
Silvers-145
commited on
Commit
•
d92103a
1
Parent(s):
be91cb0
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
|
4 |
client = InferenceClient(
|
5 |
-
# "mistralai/
|
6 |
"Silvers-145/mistral_instruct_generation"
|
7 |
-
)
|
8 |
|
9 |
-
|
10 |
|
11 |
def format_prompt(message, history):
|
12 |
prompt = "<s>"
|
@@ -16,9 +18,7 @@ def format_prompt(message, history):
|
|
16 |
prompt += f"[INST] {message} [/INST]"
|
17 |
return prompt
|
18 |
|
19 |
-
def generate(
|
20 |
-
prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
21 |
-
):
|
22 |
temperature = float(temperature)
|
23 |
if temperature < 1e-2:
|
24 |
temperature = 1e-2
|
@@ -30,10 +30,11 @@ def generate(
|
|
30 |
top_p=top_p,
|
31 |
repetition_penalty=repetition_penalty,
|
32 |
do_sample=True,
|
33 |
-
seed=
|
34 |
)
|
35 |
|
36 |
-
formatted_prompt = format_prompt(
|
|
|
37 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
38 |
output = ""
|
39 |
|
@@ -44,11 +45,6 @@ def generate(
|
|
44 |
|
45 |
|
46 |
additional_inputs=[
|
47 |
-
gr.Textbox(
|
48 |
-
label="System Prompt",
|
49 |
-
max_lines=1,
|
50 |
-
interactive=True,
|
51 |
-
),
|
52 |
gr.Slider(
|
53 |
label="Temperature",
|
54 |
value=0.9,
|
@@ -60,9 +56,9 @@ additional_inputs=[
|
|
60 |
),
|
61 |
gr.Slider(
|
62 |
label="Max new tokens",
|
63 |
-
value=
|
64 |
-
minimum=
|
65 |
-
maximum=
|
66 |
step=64,
|
67 |
interactive=True,
|
68 |
info="The maximum numbers of new tokens",
|
@@ -87,19 +83,17 @@ additional_inputs=[
|
|
87 |
)
|
88 |
]
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
|
99 |
-
fn=generate,
|
100 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
101 |
-
additional_inputs=additional_inputs,
|
102 |
-
title="Mixtral 46.7B",
|
103 |
-
examples=examples,
|
104 |
-
concurrency_limit=20,
|
105 |
-
).launch(show_api=False)
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
+
import random
|
4 |
+
|
5 |
+
API_URL = "https://api-inference.huggingface.co/models/"
|
6 |
|
7 |
client = InferenceClient(
|
8 |
+
# "mistralai/Mistral-7B-Instruct-v0.1"
|
9 |
"Silvers-145/mistral_instruct_generation"
|
|
|
10 |
|
11 |
+
)
|
12 |
|
13 |
def format_prompt(message, history):
|
14 |
prompt = "<s>"
|
|
|
18 |
prompt += f"[INST] {message} [/INST]"
|
19 |
return prompt
|
20 |
|
21 |
+
def generate(prompt, history, temperature=0.9, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
|
22 |
temperature = float(temperature)
|
23 |
if temperature < 1e-2:
|
24 |
temperature = 1e-2
|
|
|
30 |
top_p=top_p,
|
31 |
repetition_penalty=repetition_penalty,
|
32 |
do_sample=True,
|
33 |
+
seed=random.randint(0, 10**7),
|
34 |
)
|
35 |
|
36 |
+
formatted_prompt = format_prompt(prompt, history)
|
37 |
+
|
38 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
39 |
output = ""
|
40 |
|
|
|
45 |
|
46 |
|
47 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
|
48 |
gr.Slider(
|
49 |
label="Temperature",
|
50 |
value=0.9,
|
|
|
56 |
),
|
57 |
gr.Slider(
|
58 |
label="Max new tokens",
|
59 |
+
value=512,
|
60 |
+
minimum=64,
|
61 |
+
maximum=1024,
|
62 |
step=64,
|
63 |
interactive=True,
|
64 |
info="The maximum numbers of new tokens",
|
|
|
83 |
)
|
84 |
]
|
85 |
|
86 |
+
customCSS = """
|
87 |
+
#component-7 { # this is the default element ID of the chat component
|
88 |
+
height: 800px; # adjust the height as needed
|
89 |
+
flex-grow: 1;
|
90 |
+
}
|
91 |
+
"""
|
92 |
+
|
93 |
+
with gr.Blocks(css=customCSS) as demo:
|
94 |
+
gr.ChatInterface(
|
95 |
+
generate,
|
96 |
+
additional_inputs=additional_inputs,
|
97 |
+
)
|
98 |
|
99 |
+
demo.queue().launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|