cyberandy commited on
Commit
6250865
·
verified ·
1 Parent(s): 95b17ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -5,6 +5,8 @@ import pandas as pd
5
  import plotly.express as px
6
  from nltk.sentiment.vader import SentimentIntensityAnalyzer
7
  import nltk
 
 
8
 
9
  # Initialize Meta AI API
10
  ai = MetaAI()
@@ -78,10 +80,19 @@ def advanced_analysis(query, response_message):
78
  return analysis_response
79
 
80
  def parse_analysis(analysis_message):
81
- # Assuming the response message contains a JSON string starting with 'Here is the JSON:'
82
- json_str = analysis_message.split('Here is the JSON:\n')[1].strip()
83
- analysis_data = json.loads(json_str)
84
- return analysis_data
 
 
 
 
 
 
 
 
 
85
 
86
  # ---------------------------------------------------------------------------- #
87
  # Main Function
 
5
  import plotly.express as px
6
  from nltk.sentiment.vader import SentimentIntensityAnalyzer
7
  import nltk
8
+ import json
9
+
10
 
11
  # Initialize Meta AI API
12
  ai = MetaAI()
 
80
  return analysis_response
81
 
82
  def parse_analysis(analysis_message):
83
+ try:
84
+ # Check if the expected delimiter 'Here is the JSON:' is present
85
+ if 'JSON:\n' in analysis_message:
86
+ json_str = analysis_message.split('JSON:\n')[1].strip()
87
+ analysis_data = json.loads(json_str)
88
+ return analysis_data
89
+ else:
90
+ # If the delimiter is not found, return a default error message or handle it
91
+ return {"error": "JSON delimiter not found in response"}
92
+ except json.JSONDecodeError as e:
93
+ # Handle cases where JSON decoding fails
94
+ return {"error": "Failed to decode JSON", "details": str(e)}
95
+
96
 
97
  # ---------------------------------------------------------------------------- #
98
  # Main Function