acecalisto3 commited on
Commit
6fa6f73
1 Parent(s): 2c588b7

Update app.py

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