cyberandy commited on
Commit
bc63486
1 Parent(s): 7f00f39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -104,19 +104,18 @@ def fetch_advanced_analysis(query, msg):
104
 
105
  def parse_analysis(analysis_message):
106
  try:
107
- # Check if the expected delimiter 'Here is the JSON:' is present
108
- if 'JSON:\n' in analysis_message:
109
- json_str = analysis_message.split('JSON:\n')[1].strip()
 
 
 
110
  analysis_data = json.loads(json_str)
111
  return analysis_data
112
  else:
113
- # If the delimiter is not found, return a default error message or handle it
114
- return {"error": "JSON delimiter not found in response"}
115
- st.write(json_str)
116
  except json.JSONDecodeError as e:
117
- # Handle cases where JSON decoding fails
118
  return {"error": "Failed to decode JSON", "details": str(e)}
119
-
120
 
121
  # ---------------------------------------------------------------------------- #
122
  # Main Function
@@ -156,10 +155,6 @@ def main():
156
  advanced_response = fetch_advanced_analysis(user_query, msg)
157
  advanced_msg = advanced_response.get('message', 'No advanced analysis available.')
158
 
159
- # Display the advanced analysis results in a collapsible section
160
- with st.expander("Show Advanced Analysis"):
161
- st.write(advanced_msg)
162
-
163
  # Parse the advanced analysis response
164
  analysis_data = parse_analysis(advanced_msg)
165
 
@@ -170,7 +165,15 @@ def main():
170
  else:
171
  # Display parsed data in a collapsible section
172
  with st.expander("Show Advanced Analysis"):
173
- st.write(advanced_msg)
 
 
 
 
 
 
 
 
174
 
175
  # Display the sentiment in a collapsible section
176
  with st.expander("Show Sentiment"):
 
104
 
105
  def parse_analysis(analysis_message):
106
  try:
107
+ # Find the starting point of the JSON string
108
+ start = analysis_message.find('{')
109
+ if start != -1:
110
+ # Extract the JSON string
111
+ json_str = analysis_message[start:]
112
+ # Convert string to a Python dictionary
113
  analysis_data = json.loads(json_str)
114
  return analysis_data
115
  else:
116
+ return {"error": "JSON data not found in the response"}
 
 
117
  except json.JSONDecodeError as e:
 
118
  return {"error": "Failed to decode JSON", "details": str(e)}
 
119
 
120
  # ---------------------------------------------------------------------------- #
121
  # Main Function
 
155
  advanced_response = fetch_advanced_analysis(user_query, msg)
156
  advanced_msg = advanced_response.get('message', 'No advanced analysis available.')
157
 
 
 
 
 
158
  # Parse the advanced analysis response
159
  analysis_data = parse_analysis(advanced_msg)
160
 
 
165
  else:
166
  # Display parsed data in a collapsible section
167
  with st.expander("Show Advanced Analysis"):
168
+ st.write("### User Intent")
169
+ st.write(analysis_data['user_intent'])
170
+ st.write("### Follow-up Questions")
171
+ for question in analysis_data['follow_up_questions']:
172
+ st.write("- " + question)
173
+ st.write("### Identified Entities")
174
+ for entity_type, entities in analysis_data['entities'].items():
175
+ st.write(f"**{entity_type.capitalize()}**: {', '.join(entities)}")
176
+
177
 
178
  # Display the sentiment in a collapsible section
179
  with st.expander("Show Sentiment"):