cyberandy commited on
Commit
4843ba8
·
verified ·
1 Parent(s): f9309d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -34
app.py CHANGED
@@ -139,31 +139,30 @@ def main():
139
  # User input
140
  user_query = st.text_area("Enter your query:", height=150)
141
  submit_button = st.button("Analyze Query")
 
 
142
 
143
- if submit_button and user_query:
144
- # Fetching response from Meta AI
145
- response = fetch_response(user_query)
146
- msg = response.get('message', 'No response message.')
147
- # Write response
148
- st.write(msg)
149
-
150
- # Run sentiment analysis
151
- df_sentiment = sentiment_analysis(msg)
152
-
153
- # Fetch advanced analysis
154
- advanced_response = fetch_advanced_analysis(user_query, msg)
155
- advanced_msg = advanced_response.get('message', 'No advanced analysis available.')
156
-
157
- # Parse the advanced analysis response
158
- analysis_data = parse_analysis(advanced_msg)
159
 
160
- if "error" in analysis_data:
161
- st.error("Error in analysis: " + analysis_data["error"])
162
- if "details" in analysis_data:
163
- st.error("Details: " + analysis_data["details"])
164
- else:
165
- # Display parsed data in a collapsible section
166
- with st.expander("Show Advanced Analysis"):
 
 
 
 
 
 
 
 
 
167
  st.write("### User Intent")
168
  st.write(analysis_data['user_intent'])
169
  st.write("### Follow-up Questions")
@@ -173,10 +172,10 @@ def main():
173
  for entity_type, entities in analysis_data['entities'].items():
174
  st.write(f"**{entity_type.capitalize()}**: {', '.join(entities)}")
175
 
176
-
177
- # Display the sentiment in a collapsible section
178
- with st.expander("Show Sentiment"):
179
- # Display negative sentence locations
180
  fig = px.scatter(df_sentiment, y='dominant_sentiment', color='dominant_sentiment', size='confidence',
181
  hover_data=['content'],
182
  color_discrete_map={"neg": "firebrick", "neu": "navajowhite", "pos": "darkgreen"},
@@ -184,11 +183,6 @@ def main():
184
  title='Sentiment Analysis of the Response')
185
  fig.update_layout(width=800, height=300)
186
  st.plotly_chart(fig)
187
-
188
- # Display the AI response in a collapsible section
189
- with st.expander("Show Sources"):
190
- # Display sources with clickable links in a collapsible section
191
- display_sources(response.get('sources', []))
192
-
193
  if __name__ == "__main__":
194
- main()
 
139
  # User input
140
  user_query = st.text_area("Enter your query:", height=150)
141
  submit_button = st.button("Analyze Query")
142
+ # Create tabs
143
+ tab1, tab2, tab3 = st.tabs(["Overview", "Analysis", "Sentiment"])
144
 
145
+ # Tab 1: Overview - Showing the initial response and sources
146
+ with tab1:
147
+ user_query = st.text_area("Enter your query:", height=150)
148
+ submit_button = st.button("Analyze Query")
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
+ if submit_button and user_query:
151
+ response = fetch_response(user_query)
152
+ msg = response.get('message', 'No response message.')
153
+ st.write(msg)
154
+
155
+ with st.expander("Show Sources"):
156
+ display_sources(response.get('sources', []))
157
+
158
+ # Tab 2: Analysis - Showing the result of the advanced analysis
159
+ with tab2:
160
+ if submit_button and user_query:
161
+ advanced_response = fetch_advanced_analysis(user_query, msg)
162
+ advanced_msg = advanced_response.get('message', 'No advanced analysis available.')
163
+ analysis_data = parse_analysis(advanced_msg)
164
+
165
+ if "error" not in analysis_data:
166
  st.write("### User Intent")
167
  st.write(analysis_data['user_intent'])
168
  st.write("### Follow-up Questions")
 
172
  for entity_type, entities in analysis_data['entities'].items():
173
  st.write(f"**{entity_type.capitalize()}**: {', '.join(entities)}")
174
 
175
+ # Tab 3: Sentiment - Displaying sentiment analysis of the response
176
+ with tab3:
177
+ if submit_button and user_query:
178
+ df_sentiment = sentiment_analysis(msg)
179
  fig = px.scatter(df_sentiment, y='dominant_sentiment', color='dominant_sentiment', size='confidence',
180
  hover_data=['content'],
181
  color_discrete_map={"neg": "firebrick", "neu": "navajowhite", "pos": "darkgreen"},
 
183
  title='Sentiment Analysis of the Response')
184
  fig.update_layout(width=800, height=300)
185
  st.plotly_chart(fig)
186
+
 
 
 
 
 
187
  if __name__ == "__main__":
188
+ main()