Chris4K commited on
Commit
cddf298
·
verified ·
1 Parent(s): 2ea8b67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -22
app.py CHANGED
@@ -98,31 +98,16 @@ class CustomHfAgent(Agent):
98
  return result[: -len(stop_seq)]
99
  return result
100
 
101
- st.title("Hugging Face Agent and tools")
102
-
103
-
104
-
105
- # Display a welcome message
106
- with st.chat_message("assistant"):
107
- st.markdown("Hello there! How can I assist you today?")
108
-
109
- # Input field for the user's message
110
- user_message = st.text_input("User:", key="user_input")
111
-
112
- # Checkboxes for the tools to be used by the agent
113
- tool_checkboxes = [st.checkbox(f"Use {tool.name} --- {tool.description} ") for tool in tools]
114
-
115
- # Submit button
116
- submit_button = st.button("Submit")
117
-
118
  # Define the callback function to handle the form submission
119
  def handle_submission():
120
  selected_tools = [tools[idx] for idx, checkbox in enumerate(tool_checkboxes) if checkbox]
121
  print(selected_tools)
122
  # Initialize the agent
123
  agent = CustomHfAgent(
124
- #url_endpoint="https://api-inference.huggingface.co/models/bigcode/starcoder", # mistralai/Mixtral-8x7B-v0.1
125
- url_endpoint="https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-v0.1", #
126
  token=os.environ['HF_token'],
127
  additional_tools=selected_tools,
128
  input_params={"max_new_tokens": 192},
@@ -133,6 +118,41 @@ def handle_submission():
133
 
134
  print("Agent Response\n {}".format(response))
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  # Display the agent's response
137
  with st.chat_message("assistant"):
138
  if response is None:
@@ -154,7 +174,20 @@ def handle_submission():
154
  st.markdown(response)
155
  else:
156
  st.warning("Unrecognized response type. Please try again.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
- # Add the callback function to the Streamlit app
159
- if submit_button:
160
- handle_submission()
 
98
  return result[: -len(stop_seq)]
99
  return result
100
 
101
+ #################
102
+ #################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  # Define the callback function to handle the form submission
104
  def handle_submission():
105
  selected_tools = [tools[idx] for idx, checkbox in enumerate(tool_checkboxes) if checkbox]
106
  print(selected_tools)
107
  # Initialize the agent
108
  agent = CustomHfAgent(
109
+ #url_endpoint="https://api-inference.huggingface.co/models/bigcode/starcoder", # mistralai/Mixtral-8x7B-v0.1 # bigscience/bloom
110
+ url_endpoint="https://api-inference.huggingface.co/models/bigscience/bloom", #
111
  token=os.environ['HF_token'],
112
  additional_tools=selected_tools,
113
  input_params={"max_new_tokens": 192},
 
118
 
119
  print("Agent Response\n {}".format(response))
120
 
121
+ return response
122
+
123
+ # Add the callback function to the Streamlit app
124
+ #if submit_button:
125
+ # handle_submission()
126
+ #################
127
+
128
+ ######
129
+
130
+ st.title("Hugging Face Agent and tools")
131
+
132
+ # Initialize chat history
133
+ if "messages" not in st.session_state:
134
+ st.session_state.messages = []
135
+
136
+ # Display chat messages from history on app rerun
137
+ for message in st.session_state.messages:
138
+ with st.chat_message(message["role"]):
139
+ st.markdown(message["content"])
140
+
141
+ # Display a welcome message
142
+ with st.chat_message("assistant"):
143
+ st.markdown("Hello there! How can I assist you today?")
144
+
145
+ # Input field for the user's message
146
+ #user_message = st.chat_input("Enter message")
147
+
148
+ # React to user input
149
+ if user_message := st.chat_input("Enter message")
150
+ # Display user message in chat message container
151
+ st.chat_message("user").markdown(prompt)
152
+ # Add user message to chat history
153
+ st.session_state.messages.append({"role": "user", "content": prompt})
154
+
155
+ response = handle_submission
156
  # Display the agent's response
157
  with st.chat_message("assistant"):
158
  if response is None:
 
174
  st.markdown(response)
175
  else:
176
  st.warning("Unrecognized response type. Please try again.")
177
+
178
+
179
+ # Display assistant response in chat message container
180
+ #with st.chat_message("assistant"):
181
+ # st.markdown(response)
182
+ # Add assistant response to chat history
183
+ st.session_state.messages.append({"role": "assistant", "content": response})
184
+
185
+
186
+ # Submit button
187
+ #submit_button = st.button("Submit")
188
+
189
+ # Checkboxes for the tools to be used by the agent
190
+ tool_checkboxes = [st.checkbox(f"{tool.name} --- {tool.description} ") for tool in tools]
191
+
192
+
193