Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,20 @@ from huggingface_hub import InferenceClient
|
|
2 |
import gradio as gr
|
3 |
import random
|
4 |
import prompts
|
5 |
-
|
6 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
7 |
|
8 |
def format_prompt(message, history):
|
9 |
-
prompt = "<s>"
|
10 |
-
for user_prompt, bot_response in history:
|
11 |
-
prompt += f"[INST] {user_prompt} [/INST]"
|
12 |
-
prompt += f" {bot_response}</s> "
|
13 |
-
prompt += f"[INST] {message} [/INST]"
|
14 |
-
return prompt
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
print(seed)
|
18 |
system_prompt = prompts.ARTICLE_WRITER.format(history=history)
|
19 |
generate_kwargs = dict(
|
@@ -24,14 +26,16 @@ def generate(prompt, history, max_new_tokens, seed):
|
|
24 |
do_sample=True,
|
25 |
seed=seed,
|
26 |
)
|
|
|
27 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
28 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
29 |
output = ""
|
|
|
30 |
for response in stream:
|
31 |
output += response.token.text
|
32 |
-
|
33 |
|
34 |
-
additional_inputs = [
|
35 |
gr.Slider(
|
36 |
label="Max new tokens",
|
37 |
value=4096,
|
@@ -41,6 +45,7 @@ additional_inputs = [
|
|
41 |
interactive=True,
|
42 |
info="The maximum numbers of words the chatbot will return",
|
43 |
),
|
|
|
44 |
gr.Slider(
|
45 |
label="Seed",
|
46 |
value=random.randint(1,9999999999999999),
|
@@ -51,18 +56,15 @@ additional_inputs = [
|
|
51 |
info="Each seed produces a different output to a single prompt",
|
52 |
),
|
53 |
]
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
["Create a 3000-word piece exploring the role of art in shaping cultural identity."],
|
60 |
-
]
|
61 |
-
|
62 |
gr.ChatInterface(
|
63 |
fn=generate,
|
64 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
65 |
-
title="
|
66 |
additional_inputs=additional_inputs,
|
67 |
examples=examples,
|
68 |
concurrency_limit=20,
|
|
|
2 |
import gradio as gr
|
3 |
import random
|
4 |
import prompts
|
|
|
5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
|
7 |
def format_prompt(message, history):
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
prompt = "<s>"
|
10 |
+
for user_prompt, bot_response in history:
|
11 |
+
print (bot_response)
|
12 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
13 |
+
prompt += f" {bot_response}</s> "
|
14 |
+
prompt += f"[INST] {message} [/INST]"
|
15 |
+
return prompt
|
16 |
+
|
17 |
+
def generate(prompt,history,max_new_tokens,seed):
|
18 |
+
#seed = random.randint(1,9999999999999)
|
19 |
print(seed)
|
20 |
system_prompt = prompts.ARTICLE_WRITER.format(history=history)
|
21 |
generate_kwargs = dict(
|
|
|
26 |
do_sample=True,
|
27 |
seed=seed,
|
28 |
)
|
29 |
+
|
30 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
31 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
32 |
output = ""
|
33 |
+
|
34 |
for response in stream:
|
35 |
output += response.token.text
|
36 |
+
yield output
|
37 |
|
38 |
+
additional_inputs = [
|
39 |
gr.Slider(
|
40 |
label="Max new tokens",
|
41 |
value=4096,
|
|
|
45 |
interactive=True,
|
46 |
info="The maximum numbers of words the chatbot will return",
|
47 |
),
|
48 |
+
|
49 |
gr.Slider(
|
50 |
label="Seed",
|
51 |
value=random.randint(1,9999999999999999),
|
|
|
56 |
info="Each seed produces a different output to a single prompt",
|
57 |
),
|
58 |
]
|
59 |
+
examples=[["Write a heavy metal rock song about horses (1000 words)"],
|
60 |
+
["Write a really long song about an elephant love story. The elephants have been together for a long time. (3000 words)"],
|
61 |
+
["Write a slammin rap song about about a gangster fising trip."],
|
62 |
+
["Use the same lyrics as above, but add more words to each verse"],
|
63 |
+
]
|
|
|
|
|
|
|
64 |
gr.ChatInterface(
|
65 |
fn=generate,
|
66 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
67 |
+
title="ARTICLE_WRITER",
|
68 |
additional_inputs=additional_inputs,
|
69 |
examples=examples,
|
70 |
concurrency_limit=20,
|