acecalisto3 commited on
Commit
760245f
·
verified ·
1 Parent(s): 7060c4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -3,7 +3,6 @@ import os
3
  import subprocess
4
  import random
5
  from huggingface_hub import InferenceClient
6
- import gradio as gr
7
  from safe_search import safe_search
8
  from i_search import google
9
  from i_search import i_search as i_s
@@ -44,7 +43,7 @@ logger = logging.getLogger(__name__)
44
  # Load custom prompts
45
  try:
46
  with open('custom_prompts.yaml', 'r') as fp:
47
- custom_prompts = yaml.load(fp, Loader=yaml.FullLoader)
48
  except FileNotFoundError:
49
  custom_prompts = {
50
  "WEB_DEV": "",
@@ -285,7 +284,7 @@ def run_action(purpose, task, history, directory, action_name, action_input):
285
  print("COMPRESSING HISTORY")
286
  history = compress_history(purpose, task, history, directory)
287
 
288
- if not action_name in NAME_TO_FUNC:
289
  action_name = "MAIN"
290
  if action_name == "" or action_name is None:
291
  action_name = "MAIN"
@@ -327,10 +326,10 @@ def run(purpose, history):
327
  action_input,
328
  )
329
 
330
- yield (history)
331
 
332
  if task == "END":
333
- return (history)
334
 
335
  ################################################
336
 
@@ -344,14 +343,14 @@ def generate(
344
  prompt, history, agent_name=agents[0], sys_prompt="", temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.7,
345
  ):
346
  seed = random.randint(1, 1111111111111111)
347
- agent = prompts["WEB_DEV"]
348
 
349
  if agent_name == "WEB_DEV":
350
- agent = prompts["WEB_DEV"]
351
  elif agent_name == "AI_SYSTEM_PROMPT":
352
- agent = prompts["AI_SYSTEM_PROMPT"]
353
  elif agent_name == "PYTHON_CODE_DEV":
354
- agent = prompts["PYTHON_CODE_DEV"]
355
 
356
  system_prompt = agent
357
  temperature = float(temperature)
@@ -389,15 +388,15 @@ with gr.Blocks() as iface:
389
 
390
  iface.load(inputs, events)
391
  def log_messages(inputs, outputs):
392
- logger(f'Input: {inputs}, Output: {outputs}')
393
 
394
  @gr.Interface.load(inputs, agents)
395
  def log_messages(inputs, outputs):
396
- logger(f'Input: {inputs}, Output: {outputs}')
397
 
398
  @gr.Interface.load(inputs, events)
399
  def log_messages(inputs, outputs):
400
- logger(f'Input: {inputs}, Output: {outputs}')
401
 
402
  def update_sys_prompt(agent):
403
  global SYSTEM_PROMPT
@@ -514,9 +513,10 @@ with iface:
514
  [msg, chatbot, agent_dropdown, sys_prompt, temperature, max_new_tokens, top_p, repetition_penalty],
515
  [chatbot, msg])
516
  clear.click(lambda: None, None, chatbot, queue=False)
517
- gr.Examples(examples, [msg, agent_dropdown, sys_prompt, temperature, max_new_tokens, top_p, repetition_penalty]),
518
 
519
- iface.load(fn=get_helpful_tip, inputs=agent_dropdown, outputs=ui.info),
520
- iface.load(fn=update_sys_prompt, inputs=agent_dropdown, outputs=sys_prompt),
521
- iface.load(fn=log_messages, input_type= state, event_type= save_model)
 
 
522
  iface.launch()
 
3
  import subprocess
4
  import random
5
  from huggingface_hub import InferenceClient
 
6
  from safe_search import safe_search
7
  from i_search import google
8
  from i_search import i_search as i_s
 
43
  # Load custom prompts
44
  try:
45
  with open('custom_prompts.yaml', 'r') as fp:
46
+ custom_prompts = yaml.safe_load(fp)
47
  except FileNotFoundError:
48
  custom_prompts = {
49
  "WEB_DEV": "",
 
284
  print("COMPRESSING HISTORY")
285
  history = compress_history(purpose, task, history, directory)
286
 
287
+ if action_name not in NAME_TO_FUNC:
288
  action_name = "MAIN"
289
  if action_name == "" or action_name is None:
290
  action_name = "MAIN"
 
326
  action_input,
327
  )
328
 
329
+ yield history
330
 
331
  if task == "END":
332
+ return history
333
 
334
  ################################################
335
 
 
343
  prompt, history, agent_name=agents[0], sys_prompt="", temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.7,
344
  ):
345
  seed = random.randint(1, 1111111111111111)
346
+ agent = custom_prompts["WEB_DEV"]
347
 
348
  if agent_name == "WEB_DEV":
349
+ agent = custom_prompts["WEB_DEV"]
350
  elif agent_name == "AI_SYSTEM_PROMPT":
351
+ agent = custom_prompts["AI_SYSTEM_PROMPT"]
352
  elif agent_name == "PYTHON_CODE_DEV":
353
+ agent = custom_prompts["PYTHON_CODE_DEV"]
354
 
355
  system_prompt = agent
356
  temperature = float(temperature)
 
388
 
389
  iface.load(inputs, events)
390
  def log_messages(inputs, outputs):
391
+ logger.info(f'Input: {inputs}, Output: {outputs}')
392
 
393
  @gr.Interface.load(inputs, agents)
394
  def log_messages(inputs, outputs):
395
+ logger.info(f'Input: {inputs}, Output: {outputs}')
396
 
397
  @gr.Interface.load(inputs, events)
398
  def log_messages(inputs, outputs):
399
+ logger.info(f'Input: {inputs}, Output: {outputs}')
400
 
401
  def update_sys_prompt(agent):
402
  global SYSTEM_PROMPT
 
513
  [msg, chatbot, agent_dropdown, sys_prompt, temperature, max_new_tokens, top_p, repetition_penalty],
514
  [chatbot, msg])
515
  clear.click(lambda: None, None, chatbot, queue=False)
 
516
 
517
+ gr.Examples(examples, [msg, agent_dropdown, sys_prompt, temperature, max_new_tokens, top_p, repetition_penalty])
518
+
519
+ agent_dropdown.change(fn=get_helpful_tip, inputs=agent_dropdown, outputs=gr.components.Markdown())
520
+ agent_dropdown.change(fn=update_sys_prompt, inputs=agent_dropdown, outputs=sys_prompt)
521
+
522
  iface.launch()