acecalisto3 commited on
Commit
12548f9
·
verified ·
1 Parent(s): 37fbfcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -50
app.py CHANGED
@@ -170,8 +170,38 @@ def run_code(code):
170
 
171
  def chat_interface(message, history, agent_role, temperature=0.9, max_new_tokens=2048, top_p=0.95, repetition_penalty=1.0):
172
  """Handles user input and generates responses."""
173
- if message.startswith("```python"):
174
- # User entered code, execute it
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  code = message[9:-3]
176
  output = run_code(code)
177
  return (message, output)
@@ -181,53 +211,53 @@ def chat_interface(message, history, agent_role, temperature=0.9, max_new_tokens
181
  return (message, response)
182
 
183
  with gr.Blocks(theme='ParityError/Interstellar') as demo:
184
- with gr.Row():
185
- for agent_name, agent_data in agent_roles.items():
186
- gr.Button(agent_name, variant="secondary").click(toggle_agent, inputs=[gr.Button], outputs=[gr.Textbox])
187
- gr.Textbox(agent_data["description"], interactive=False)
188
-
189
  with gr.Row():
190
- gr.ChatInterface(
191
- chat_interface,
192
- additional_inputs=[
193
- gr.Slider(
194
- label="Temperature",
195
- value=0.9,
196
- minimum=0.0,
197
- maximum=1.0,
198
- step=0.05,
199
- interactive=True,
200
- info="Higher values generate more diverse outputs",
201
- ),
202
- gr.Slider(
203
- label="Maximum New Tokens",
204
- value=2048,
205
- minimum=64,
206
- maximum=4096,
207
- step=64,
208
- interactive=True,
209
- info="The maximum number of new tokens",
210
- ),
211
- gr.Slider(
212
- label="Top-p (Nucleus Sampling)",
213
- value=0.90,
214
- minimum=0.0,
215
- maximum=1,
216
- step=0.05,
217
- interactive=True,
218
- info="Higher values sample more low-probability tokens",
219
- ),
220
- gr.Slider(
221
- label="Repetition Penalty",
222
- value=1.2,
223
- minimum=1.0,
224
- maximum=2.0,
225
- step=0.05,
226
- interactive=True,
227
- info="Penalize repeated tokens",
228
- )
229
- ],
230
- inputs=[gr.Textbox, gr.Chatbot, get_agent_cluster],
231
- )
 
 
 
 
 
232
 
233
- demo.queue().launch(debug=True)
 
170
 
171
  def chat_interface(message, history, agent_role, temperature=0.9, max_new_tokens=2048, top_p=0.95, repetition_penalty=1.0):
172
  """Handles user input and generates responses."""
173
+ if message.startswith("
174
+
175
+
176
+ python"): # User entered code, execute it code = message[9:-3] output = run_code(code) return (message, output) else: # User entered a normal message, generate a response response = generate(message, history, agent_role, temperature, max_new_tokens, top_p, repetition_penalty) return (message, response)
177
+
178
+ Define the available agent roles
179
+ agent_roles = { "Web Developer": {"description": "A master of front-end and back-end web development.", "active": False}, "Prompt Engineer": {"description": "An expert in crafting effective prompts for AI models.", "active": False}, "Python Code Developer": {"description": "A skilled Python programmer who can write clean and efficient code.", "active": False}, "Hugging Face Hub Expert": {"description": "A specialist in navigating and utilizing the Hugging Face Hub.", "active": False}, "AI-Powered Code Assistant": {"description": "An AI assistant that can help with coding tasks and provide code snippets.", "active": False}, }
180
+
181
+ Initialize the selected agent
182
+ selected_agent = list(agent_roles.keys())[0]
183
+
184
+ Define the initial prompt for the selected agent
185
+ initial_prompt = f""" You are an expert {selected_agent} who responds with complete program coding to client requests. Using available tools, please explain the researched information. Please don't answer based solely on what you already know. Always perform a search before providing a response. In special cases, such as when the user specifies a page to read, there's no need to search. Please read the provided page and answer the user's question accordingly. If you find that there's not much information just by looking at the search results page, consider these two options and try them out:
186
+
187
+ Try clicking on the links of the search results to access and read the content of each page.
188
+ Change your search query and perform a new search. Users are extremely busy and not as free as you are. Therefore, to save the user's effort, please provide direct answers. BAD ANSWER EXAMPLE
189
+ Please refer to these pages.
190
+ You can write code referring these pages.
191
+ Following page will be helpful. GOOD ANSWER EXAMPLE
192
+ This is the complete code: -- complete code here --
193
+ The answer of you question is -- answer here -- Please make sure to list the URLs of the pages you referenced at the end of your answer. (This will allow users to verify your response.) Please make sure to answer in the language used by the user. If the user asks in Japanese, please answer in Japanese. If the user asks in Spanish, please answer in Spanish. But, you can go ahead and search in English, especially for programming-related questions. PLEASE MAKE SURE TO ALWAYS SEARCH IN ENGLISH FOR THOSE. """
194
+ customCSS = """ #component-7 { # dies ist die Standardelement-ID des Chatkomponenten height: 1600px; # passen Sie die Höhe nach Bedarf an flex-grow: 4; } """
195
+
196
+ def toggle_agent(agent_name): """Toggles the active state of an agent.""" global agent_roles agent_roles[agent_name]["active"] = not agent_roles[agent_name]["active"] return f"{agent_name} is now {'active' if agent_roles[agent_name]['active'] else 'inactive'}"
197
+
198
+ def get_agent_cluster(): """Returns a dictionary of active agents.""" return {agent: agent_roles[agent]["active"] for agent in agent_roles}
199
+
200
+ def run_code(code): """Executes the provided code and returns the output.""" try: output = subprocess.check_output( ['python', '-c', code], stderr=subprocess.STDOUT, universal_newlines=True, ) return output except subprocess.CalledProcessError as e: return f"Error: {e.output}"
201
+
202
+ def chat_interface(message, history, agent_role, temperature=0.9, max_new_tokens=2048, top_p=0.95, repetition_penalty=1.0): """Handles user input and generates responses.""" if message.startswith("
203
+
204
+ # User entered code, execute it
205
  code = message[9:-3]
206
  output = run_code(code)
207
  return (message, output)
 
211
  return (message, response)
212
 
213
  with gr.Blocks(theme='ParityError/Interstellar') as demo:
 
 
 
 
 
214
  with gr.Row():
215
+ for agent_name, agent_data in agent_roles.items():
216
+ gr.Button(agent_name, variant="secondary").click(toggle_agent, inputs=[gr.Button], outputs=[gr.Textbox])
217
+ gr.Textbox(agent_data["description"], interactive=False)
218
+
219
+ with gr.Row():
220
+ gr.ChatInterface(
221
+ chat_interface,
222
+ additional_inputs=[
223
+ gr.Slider(
224
+ label="Temperature",
225
+ value=0.9,
226
+ minimum=0.0,
227
+ maximum=1.0,
228
+ step=0.05,
229
+ interactive=True,
230
+ info="Higher values generate more diverse outputs",
231
+ ),
232
+ gr.Slider(
233
+ label="Maximum New Tokens",
234
+ value=2048,
235
+ minimum=64,
236
+ maximum=4096,
237
+ step=64,
238
+ interactive=True,
239
+ info="The maximum number of new tokens",
240
+ ),
241
+ gr.Slider(
242
+ label="Top-p (Nucleus Sampling)",
243
+ value=0.90,
244
+ minimum=0.0,
245
+ maximum=1,
246
+ step=0.05,
247
+ interactive=True,
248
+ info="Higher values sample more low-probability tokens",
249
+ ),
250
+ gr.Slider(
251
+ label="Repetition Penalty",
252
+ value=1.2,
253
+ minimum=1.0,
254
+ maximum=2.0,
255
+ step=0.05,
256
+ interactive=True,
257
+ info="Penalize repeated tokens",
258
+ )
259
+ ],
260
+ inputs=[gr.Textbox, gr.Chatbot, get_agent_cluster],
261
+ )
262
 
263
+ demo.queue().launch(debug=True)