Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
|
|
|
| 3 |
|
| 4 |
API_URL = "https://jj78yliqd7.execute-api.eu-central-1.amazonaws.com/dev/chatbot"
|
| 5 |
|
|
@@ -13,6 +15,14 @@ def get_response(prompt, history):
|
|
| 13 |
else:
|
| 14 |
return "Sorry, something went wrong. Please try again."
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Streamlit App
|
| 17 |
st.sidebar.title("Wissensguru - IDTA")
|
| 18 |
|
|
@@ -39,9 +49,19 @@ if user_query is not None and user_query != "":
|
|
| 39 |
# Generate bot's response
|
| 40 |
response = get_response(user_query, st.session_state.chat_history)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Append messages to chat history
|
| 47 |
st.session_state.chat_history.append(HumanMessage(content=user_query))
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
|
| 6 |
API_URL = "https://jj78yliqd7.execute-api.eu-central-1.amazonaws.com/dev/chatbot"
|
| 7 |
|
|
|
|
| 15 |
else:
|
| 16 |
return "Sorry, something went wrong. Please try again."
|
| 17 |
|
| 18 |
+
# Regular expression to extract JSON object from text
|
| 19 |
+
def extract_json(text):
|
| 20 |
+
json_data = re.search(r'\{.*\}', text, re.DOTALL)
|
| 21 |
+
if json_data:
|
| 22 |
+
return json_data.group(0)
|
| 23 |
+
else:
|
| 24 |
+
return None
|
| 25 |
+
|
| 26 |
# Streamlit App
|
| 27 |
st.sidebar.title("Wissensguru - IDTA")
|
| 28 |
|
|
|
|
| 49 |
# Generate bot's response
|
| 50 |
response = get_response(user_query, st.session_state.chat_history)
|
| 51 |
|
| 52 |
+
# Extract JSON from bot's response
|
| 53 |
+
extracted_json = extract_json(response)
|
| 54 |
+
|
| 55 |
+
if extracted_json:
|
| 56 |
+
# Parse JSON string into a dictionary
|
| 57 |
+
data_dict = json.loads(extracted_json)
|
| 58 |
+
|
| 59 |
+
# Display JSON in Streamlit
|
| 60 |
+
st.json(data_dict)
|
| 61 |
+
else:
|
| 62 |
+
# Display bot's response if JSON extraction fails
|
| 63 |
+
with st.chat_message("AI"):
|
| 64 |
+
st.write(response)
|
| 65 |
|
| 66 |
# Append messages to chat history
|
| 67 |
st.session_state.chat_history.append(HumanMessage(content=user_query))
|