Chris4K commited on
Commit
bd4ac0b
·
verified ·
1 Parent(s): fb5ba89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -30,11 +30,11 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, Agent, LocalAgent
30
  # print(agent.run("Is the following `text` (in Spanish) positive or negative?", text="¡Este es un API muy agradable!"))
31
 
32
  # Load tools
33
- random-character-tool = load_tool("Chris4K/random-character-tool")
34
- text-generation-tool = load_tool("Chris4K/text-generation-tool")
35
 
36
 
37
- tools = [random-character-tool, text-generation-tool]
38
 
39
  # Define the custom HfAgent class
40
  class CustomHfAgent(Agent):
@@ -87,6 +87,15 @@ tool_checkboxes = [st.checkbox(f"Use {tool.name} --- {tool.description} ") for t
87
  # Submit button
88
  #submit_button = st.button("Submit")
89
 
 
 
 
 
 
 
 
 
 
90
  # Define the callback function to handle the form submission
91
  def handle_submission():
92
  # Get the user's message and the selected tools
@@ -94,19 +103,15 @@ def handle_submission():
94
 
95
  #selected_tools = []
96
  selected_tools = [tool for idx, tool in enumerate(tools) if tool_checkboxes[idx]]
 
97
  print(selected_tools)
98
 
99
- # Initialize the agent
100
- agent = CustomHfAgent(
101
- url_endpoint="https://api-inference.huggingface.co/models/bigcode/starcoder",
102
- token=os.environ['HF_token'],
103
- additional_tools=selected_tools,
104
- input_params={"max_new_tokens": 192}, # Set the desired value
105
- )
106
 
 
107
  # Run the agent with the user's message and selected tools
108
- response = agent.run(message)
109
- #response = agent.chat(message)
110
 
111
  print("Response " + response)
112
 
 
30
  # print(agent.run("Is the following `text` (in Spanish) positive or negative?", text="¡Este es un API muy agradable!"))
31
 
32
  # Load tools
33
+ random_character_tool = load_tool("Chris4K/random-character-tool")
34
+ text_generation_tool = load_tool("Chris4K/text-generation-tool")
35
 
36
 
37
+ tools = [random_character_tool, text_generation_tool]
38
 
39
  # Define the custom HfAgent class
40
  class CustomHfAgent(Agent):
 
87
  # Submit button
88
  #submit_button = st.button("Submit")
89
 
90
+ # Initialize the agent
91
+ agent = CustomHfAgent(
92
+ url_endpoint="https://api-inference.huggingface.co/models/bigcode/starcoder",
93
+ token=os.environ['HF_token'],
94
+ additional_tools=selected_tools,
95
+ input_params={"max_new_tokens": 192}, # Set the desired value
96
+ )
97
+
98
+
99
  # Define the callback function to handle the form submission
100
  def handle_submission():
101
  # Get the user's message and the selected tools
 
103
 
104
  #selected_tools = []
105
  selected_tools = [tool for idx, tool in enumerate(tools) if tool_checkboxes[idx]]
106
+
107
  print(selected_tools)
108
 
109
+ agent.tools = selected_tools
 
 
 
 
 
 
110
 
111
+
112
  # Run the agent with the user's message and selected tools
113
+ #response = agent.run(message)
114
+ response = agent.chat(message)
115
 
116
  print("Response " + response)
117