Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ openai.api_key = os.getenv("API_KEY")
|
|
| 12 |
# Define a dictionary to store the conversation history for each session
|
| 13 |
conversation_histories = {}
|
| 14 |
|
| 15 |
-
# Streamlit app
|
| 16 |
def main():
|
| 17 |
st.title("Tech Support Chatbot")
|
| 18 |
|
|
@@ -20,13 +20,25 @@ def main():
|
|
| 20 |
if 'history' not in st.session_state:
|
| 21 |
st.session_state.history = []
|
| 22 |
|
| 23 |
-
user_input = st.text_input("Your question:", key="user_input")
|
| 24 |
|
| 25 |
-
if st.button("Ask"):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def get_message(user_input):
|
| 32 |
context = """
|
|
|
|
| 12 |
# Define a dictionary to store the conversation history for each session
|
| 13 |
conversation_histories = {}
|
| 14 |
|
| 15 |
+
# Streamlit app:
|
| 16 |
def main():
|
| 17 |
st.title("Tech Support Chatbot")
|
| 18 |
|
|
|
|
| 20 |
if 'history' not in st.session_state:
|
| 21 |
st.session_state.history = []
|
| 22 |
|
| 23 |
+
user_input = st.text_input("Your question:", key="user_input", on_change=submit_on_enter)
|
| 24 |
|
| 25 |
+
if st.button("Ask") or st.session_state.get('enter_pressed', False):
|
| 26 |
+
if user_input: # Ensuring input is not empty
|
| 27 |
+
response = get_message(user_input)
|
| 28 |
+
display_conversation(user_input, response)
|
| 29 |
+
|
| 30 |
+
def submit_on_enter():
|
| 31 |
+
if st.session_state.user_input: # Trigger only if there's input
|
| 32 |
+
st.session_state.enter_pressed = True
|
| 33 |
+
else:
|
| 34 |
+
st.session_state.enter_pressed = False
|
| 35 |
+
|
| 36 |
+
def display_conversation(user_input, response):
|
| 37 |
+
st.session_state.history.append(f"User: {user_input}")
|
| 38 |
+
st.session_state.history.append(f"IT Support: {response}")
|
| 39 |
+
for message in st.session_state.history[-10:]: # Display last 10 messages
|
| 40 |
+
st.write(message)
|
| 41 |
+
st.session_state.enter_pressed = False # Reset the enter trigger
|
| 42 |
|
| 43 |
def get_message(user_input):
|
| 44 |
context = """
|