cyberandy commited on
Commit
2ea4fdd
1 Parent(s): d6f48b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -67,6 +67,21 @@ def sentiment_analysis(text):
67
  df['confidence'] = df[['neg', 'neu', 'pos']].max(axis=1)
68
 
69
  return df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  # ---------------------------------------------------------------------------- #
72
  # Main Function
@@ -102,6 +117,24 @@ def main():
102
  # Run sentiment analysis
103
  df_sentiment = sentiment_analysis(msg)
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  # Display the sentiment in a collapsible section
106
  with st.expander("Show Sentiment"):
107
  # Display negative sentence locations
 
67
  df['confidence'] = df[['neg', 'neu', 'pos']].max(axis=1)
68
 
69
  return df
70
+
71
+ # ---------------------------------------------------------------------------- #
72
+ # Advanced Analysis
73
+ # ---------------------------------------------------------------------------- #
74
+
75
+ def advanced_analysis(query, response_message):
76
+ analysis_prompt = f"Analyze the question of the user '{query}', analyze the response '{response_message}' and provide a JSON that includes: the user's intent, up to four follow-up questions, the entities in the response."
77
+ analysis_response = ai.prompt(message=analysis_prompt)
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
 
117
  # Run sentiment analysis
118
  df_sentiment = sentiment_analysis(msg)
119
 
120
+ # Advanced analysis with second AI call
121
+ advanced_response = advanced_analysis(user_query, msg)
122
+ advanced_msg = advanced_response.get('message', 'No advanced analysis available.')
123
+
124
+ # Parse the advanced analysis response
125
+ analysis_data = parse_analysis(advanced_msg)
126
+
127
+ # Display parsed data in a collapsible section
128
+ with st.expander("Show Advanced Analysis"):
129
+ st.write("### User Intent")
130
+ st.write(analysis_data['user_intent'])
131
+ st.write("### Follow-up Questions")
132
+ for question in analysis_data['follow_up_questions']:
133
+ st.write("- " + question)
134
+ st.write("### Identified Entities")
135
+ for entity_type, entities in analysis_data['entities'].items():
136
+ st.write(f"**{entity_type.capitalize()}**: {', '.join(entities)}")
137
+
138
  # Display the sentiment in a collapsible section
139
  with st.expander("Show Sentiment"):
140
  # Display negative sentence locations