Spaces:
Sleeping
Sleeping
acecalisto3
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,58 +2,51 @@ from huggingface_hub import InferenceClient
|
|
2 |
import gradio as gr
|
3 |
import random
|
4 |
import prompts
|
5 |
-
|
6 |
-
|
7 |
-
)
|
8 |
|
9 |
def format_prompt(message, history):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
17 |
"WEB_DEV",
|
18 |
"AI_SYSTEM_PROMPT",
|
19 |
"PYTHON_CODE_DEV",
|
20 |
"CODE_REVIEW_ASSISTANT",
|
21 |
"CONTENT_WRITER_EDITOR",
|
22 |
-
#"SOCIAL_MEDIA_MANAGER",
|
23 |
-
#"MEME_GENERATOR",
|
24 |
"QUESTION_GENERATOR",
|
25 |
-
#"IMAGE_GENERATOR",
|
26 |
"HUGGINGFACE_FILE_DEV",
|
27 |
-
|
28 |
]
|
|
|
29 |
def generate(
|
30 |
-
|
31 |
):
|
32 |
-
seed = random.randint(1,1111111111111111)
|
33 |
-
|
34 |
|
35 |
-
agent=prompts.WEB_DEV
|
36 |
if agent_name == "WEB_DEV":
|
37 |
agent = prompts.WEB_DEV_SYSTEM_PROMPT
|
38 |
-
|
39 |
agent = prompts.CODE_REVIEW_ASSISTANT
|
40 |
-
|
41 |
agent = prompts.CONTENT_WRITER_EDITOR
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
agent = prompts.AI_SYSTEM_PROMPT
|
46 |
-
|
47 |
agent = prompts.PYTHON_CODE_DEV
|
48 |
-
|
49 |
-
# agent = prompts.MEME_GENERATOR
|
50 |
-
if agent_name == "QUESTION_GENERATOR":
|
51 |
agent = prompts.QUESTION_GENERATOR
|
52 |
-
|
53 |
-
# agent = prompts.IMAGE_GENERATOR
|
54 |
-
if agent_name == "HUGGINGFACE_FILE_DEV":
|
55 |
agent = prompts.HUGGINGFACE_FILE_DEV
|
56 |
-
|
|
|
57 |
temperature = float(temperature)
|
58 |
if temperature < 1e-2:
|
59 |
temperature = 1e-2
|
@@ -77,14 +70,13 @@ def generate(
|
|
77 |
yield output
|
78 |
return output
|
79 |
|
80 |
-
|
81 |
-
additional_inputs=[
|
82 |
gr.Dropdown(
|
83 |
label="Agents",
|
84 |
choices=[s for s in agents],
|
85 |
value=agents[0],
|
86 |
interactive=True,
|
87 |
-
|
88 |
gr.Textbox(
|
89 |
label="System Prompt",
|
90 |
max_lines=1,
|
@@ -99,12 +91,11 @@ additional_inputs=[
|
|
99 |
interactive=True,
|
100 |
info="Higher values produce more diverse outputs",
|
101 |
),
|
102 |
-
|
103 |
gr.Slider(
|
104 |
label="Max new tokens",
|
105 |
-
value=1048*10,
|
106 |
minimum=0,
|
107 |
-
maximum=1048*10,
|
108 |
step=64,
|
109 |
interactive=True,
|
110 |
info="The maximum numbers of new tokens",
|
@@ -127,35 +118,32 @@ additional_inputs=[
|
|
127 |
interactive=True,
|
128 |
info="Penalize repeated tokens",
|
129 |
),
|
130 |
-
|
131 |
-
|
132 |
]
|
133 |
|
134 |
-
examples=[
|
135 |
-
["Create a simple web application using Flask", agents[0], None, None, None, None
|
136 |
-
["Generate a Python script to perform a linear regression analysis", agents[2], None, None, None, None
|
137 |
-
["Create a Dockerfile for a Node.js application", agents[1], None, None, None, None
|
138 |
-
["Write a shell script to automate the deployment of a web application to a server", agents[3], None, None, None, None
|
139 |
-
["Generate a SQL query to retrieve the top 10 most popular products by sales", agents[4], None, None, None, None
|
140 |
-
["Write a Python script to generate a random password with a given length and complexity", agents[2], None, None, None, None
|
141 |
-
["Create a simple game in Unity using C#", agents[0], None, None, None, None
|
142 |
-
["Generate a Java program to implement a binary search algorithm", agents[2], None, None, None, None
|
143 |
-
["Write a shell script to monitor the CPU usage of a server", agents[1], None, None, None, None
|
144 |
-
["Create a simple web application using React and Node.js", agents[0], None, None, None, None
|
145 |
-
["Generate a Python script to perform a sentiment analysis on a given text", agents[2], None, None, None, None
|
146 |
-
["Write a shell script to automate the backup of a MySQL database", agents[1], None, None, None, None
|
147 |
-
["Create a simple game in Unreal Engine using C++", agents[3], None, None, None, None
|
148 |
-
["Generate a Java program to implement a bubble sort algorithm", agents[2], None, None, None, None
|
149 |
-
["Write a shell script to monitor the memory usage of a server", agents[1], None, None, None, None
|
150 |
-
["Create a simple web application using Angular and Node.js", agents[0], None, None, None, None
|
151 |
-
["Generate a Python script to perform a text classification on a given dataset", agents[2], None, None, None, None
|
152 |
-
["Write a shell script to automate the installation of a software package on a server", agents[1], None, None, None, None
|
153 |
-
["Create a simple game in Godot using GDScript", agents[3], None, None, None, None
|
154 |
-
["Generate a Java program to implement a merge sort algorithm", agents[2], None, None, None, None
|
155 |
-
["Write a shell script to automate the cleanup of temporary files on a server", agents[1], None, None, None, None
|
156 |
]
|
157 |
|
158 |
-
|
159 |
gr.ChatInterface(
|
160 |
fn=generate,
|
161 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
@@ -163,6 +151,4 @@ gr.ChatInterface(
|
|
163 |
title="Mixtral 46.7B",
|
164 |
examples=examples,
|
165 |
concurrency_limit=20,
|
166 |
-
).launch(show_api=False)
|
167 |
-
|
168 |
-
|
|
|
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 |
+
agents = [
|
17 |
"WEB_DEV",
|
18 |
"AI_SYSTEM_PROMPT",
|
19 |
"PYTHON_CODE_DEV",
|
20 |
"CODE_REVIEW_ASSISTANT",
|
21 |
"CONTENT_WRITER_EDITOR",
|
|
|
|
|
22 |
"QUESTION_GENERATOR",
|
|
|
23 |
"HUGGINGFACE_FILE_DEV",
|
|
|
24 |
]
|
25 |
+
|
26 |
def generate(
|
27 |
+
prompt, history, agent_name=agents[0], sys_prompt="", temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
28 |
):
|
29 |
+
seed = random.randint(1, 1111111111111111)
|
|
|
30 |
|
31 |
+
agent = prompts.WEB_DEV
|
32 |
if agent_name == "WEB_DEV":
|
33 |
agent = prompts.WEB_DEV_SYSTEM_PROMPT
|
34 |
+
elif agent_name == "CODE_REVIEW_ASSISTANT":
|
35 |
agent = prompts.CODE_REVIEW_ASSISTANT
|
36 |
+
elif agent_name == "CONTENT_WRITER_EDITOR":
|
37 |
agent = prompts.CONTENT_WRITER_EDITOR
|
38 |
+
elif agent_name == "SOCIAL_MEDIA_MANAGER":
|
39 |
+
agent = prompts.SOCIAL_MEDIA_MANAGER
|
40 |
+
elif agent_name == "AI_SYSTEM_PROMPT":
|
41 |
agent = prompts.AI_SYSTEM_PROMPT
|
42 |
+
elif agent_name == "PYTHON_CODE_DEV":
|
43 |
agent = prompts.PYTHON_CODE_DEV
|
44 |
+
elif agent_name == "QUESTION_GENERATOR":
|
|
|
|
|
45 |
agent = prompts.QUESTION_GENERATOR
|
46 |
+
elif agent_name == "HUGGINGFACE_FILE_DEV":
|
|
|
|
|
47 |
agent = prompts.HUGGINGFACE_FILE_DEV
|
48 |
+
|
49 |
+
system_prompt = agent
|
50 |
temperature = float(temperature)
|
51 |
if temperature < 1e-2:
|
52 |
temperature = 1e-2
|
|
|
70 |
yield output
|
71 |
return output
|
72 |
|
73 |
+
additional_inputs = [
|
|
|
74 |
gr.Dropdown(
|
75 |
label="Agents",
|
76 |
choices=[s for s in agents],
|
77 |
value=agents[0],
|
78 |
interactive=True,
|
79 |
+
),
|
80 |
gr.Textbox(
|
81 |
label="System Prompt",
|
82 |
max_lines=1,
|
|
|
91 |
interactive=True,
|
92 |
info="Higher values produce more diverse outputs",
|
93 |
),
|
|
|
94 |
gr.Slider(
|
95 |
label="Max new tokens",
|
96 |
+
value=1048 * 10,
|
97 |
minimum=0,
|
98 |
+
maximum=1048 * 10,
|
99 |
step=64,
|
100 |
interactive=True,
|
101 |
info="The maximum numbers of new tokens",
|
|
|
118 |
interactive=True,
|
119 |
info="Penalize repeated tokens",
|
120 |
),
|
|
|
|
|
121 |
]
|
122 |
|
123 |
+
examples = [
|
124 |
+
["Create a simple web application using Flask", agents[0], None, None, None, None],
|
125 |
+
["Generate a Python script to perform a linear regression analysis", agents[2], None, None, None, None],
|
126 |
+
["Create a Dockerfile for a Node.js application", agents[1], None, None, None, None],
|
127 |
+
["Write a shell script to automate the deployment of a web application to a server", agents[3], None, None, None, None],
|
128 |
+
["Generate a SQL query to retrieve the top 10 most popular products by sales", agents[4], None, None, None, None],
|
129 |
+
["Write a Python script to generate a random password with a given length and complexity", agents[2], None, None, None, None],
|
130 |
+
["Create a simple game in Unity using C#", agents[0], None, None, None, None],
|
131 |
+
["Generate a Java program to implement a binary search algorithm", agents[2], None, None, None, None],
|
132 |
+
["Write a shell script to monitor the CPU usage of a server", agents[1], None, None, None, None],
|
133 |
+
["Create a simple web application using React and Node.js", agents[0], None, None, None, None],
|
134 |
+
["Generate a Python script to perform a sentiment analysis on a given text", agents[2], None, None, None, None],
|
135 |
+
["Write a shell script to automate the backup of a MySQL database", agents[1], None, None, None, None],
|
136 |
+
["Create a simple game in Unreal Engine using C++", agents[3], None, None, None, None],
|
137 |
+
["Generate a Java program to implement a bubble sort algorithm", agents[2], None, None, None, None],
|
138 |
+
["Write a shell script to monitor the memory usage of a server", agents[1], None, None, None, None],
|
139 |
+
["Create a simple web application using Angular and Node.js", agents[0], None, None, None, None],
|
140 |
+
["Generate a Python script to perform a text classification on a given dataset", agents[2], None, None, None, None],
|
141 |
+
["Write a shell script to automate the installation of a software package on a server", agents[1], None, None, None, None],
|
142 |
+
["Create a simple game in Godot using GDScript", agents[3], None, None, None, None],
|
143 |
+
["Generate a Java program to implement a merge sort algorithm", agents[2], None, None, None, None],
|
144 |
+
["Write a shell script to automate the cleanup of temporary files on a server", agents[1], None, None, None, None],
|
145 |
]
|
146 |
|
|
|
147 |
gr.ChatInterface(
|
148 |
fn=generate,
|
149 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
|
|
151 |
title="Mixtral 46.7B",
|
152 |
examples=examples,
|
153 |
concurrency_limit=20,
|
154 |
+
).launch(show_api=False)
|
|
|
|