I'm using Langchain's Human Tool as part of my application. However, I am having difficulty integrating it into streamlit.
I'm mainly trying to change the input_func
argument in the function:
Human_Tool =load_tools(["human"], lm=llm, input_func=get_input)
I've tried many different approaches but have not had success yet.
Here are some of the things I've tried:
import streamlit as st
def get_input() -> str:
st.write("Insert your text below.")
# Updated this line to include a label and hide it using label_visibility
user_input = st.text_area(label="Your Text", value="", height=100, key=None, help=None, on_change=None, args=None, kwargs=None, label_visibility="hidden")
submit_button = st.button("Submit")
if submit_button:
return user_input.strip() # This will return the text entered by the user
if not submit_button:
with st.empty():
for remaining in range(3600, 0, -1):
st.write(f"You have {remaining//60} minutes and {remaining%60} seconds to enter the text.")
time.sleep(1)
st.empty()
return "" # Returning empty if no input after an hour or not submitted
The code above opens a streamlit box that and accepts the user's input but it does not pass the users input to the agent.
import streamlit as st
import uuid
def get_input() -> str:
unique_key = str(uuid.uuid4())
user_input = st.text_area(
"Insert your text below:",
key=f"uniqueTextAreaKey_{unique_key}",
value="",
height=200,
)
if st.button("Submit", key=f"uniqueButtonKey_{unique_key}"):
if user_input: # check if user input is not empty
st.session_state['user_input'] = user_input
st.session_state['submitted'] = True
st.success("Input submitted successfully!")
return user_input.strip()
elif 'submitted' in st.session_state and st.session_state['submitted']:
st.success("Input already submitted.")
return st.session_state['user_input'].strip()
else:
st.warning("Please enter text and press submit.")
return ""
This code also opens up a streamlit text box but gets stuck in an infinite loop.
I want to ask what might be a get_input
function for langchains' Human Tool that integrates successfully with streamlit.