Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -74,10 +74,33 @@ def sentiment_analysis(text):
|
|
74 |
# Advanced Analysis
|
75 |
# ---------------------------------------------------------------------------- #
|
76 |
|
77 |
-
def
|
78 |
-
analysis_prompt = f"
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
def parse_analysis(analysis_message):
|
83 |
try:
|
@@ -129,9 +152,13 @@ def main():
|
|
129 |
# Run sentiment analysis
|
130 |
df_sentiment = sentiment_analysis(msg)
|
131 |
|
132 |
-
#
|
133 |
-
advanced_response =
|
134 |
advanced_msg = advanced_response.get('message', 'No advanced analysis available.')
|
|
|
|
|
|
|
|
|
135 |
|
136 |
# Parse the advanced analysis response
|
137 |
analysis_data = parse_analysis(advanced_msg)
|
@@ -143,15 +170,8 @@ def main():
|
|
143 |
else:
|
144 |
# Display parsed data in a collapsible section
|
145 |
with st.expander("Show Advanced Analysis"):
|
146 |
-
st.write(
|
147 |
-
|
148 |
-
st.write("### Follow-up Questions")
|
149 |
-
for question in analysis_data['follow_up_questions']:
|
150 |
-
st.write("- " + question)
|
151 |
-
st.write("### Identified Entities")
|
152 |
-
for entity_type, entities in analysis_data['entities'].items():
|
153 |
-
st.write(f"**{entity_type.capitalize()}**: {', '.join(entities)}")
|
154 |
-
|
155 |
# Display the sentiment in a collapsible section
|
156 |
with st.expander("Show Sentiment"):
|
157 |
# Display negative sentence locations
|
|
|
74 |
# Advanced Analysis
|
75 |
# ---------------------------------------------------------------------------- #
|
76 |
|
77 |
+
def fetch_advanced_analysis(query, msg):
|
78 |
+
analysis_prompt = f"""
|
79 |
+
Analyze the user's request: '{query}', and the response: '{msg}'.
|
80 |
+
Based on this analysis, generate a detailed JSON response including:
|
81 |
+
1. The user's intent,
|
82 |
+
2. Up to four follow-up questions,
|
83 |
+
3. The main entities mentioned in the response.
|
84 |
+
|
85 |
+
Example of expected JSON format:
|
86 |
+
{{
|
87 |
+
"user_intent": "Identify the effects of climate change on polar bears",
|
88 |
+
"follow_up_questions": [
|
89 |
+
"What are the primary threats to polar bears today?",
|
90 |
+
"How does the melting ice affect their habitat?",
|
91 |
+
"What conservation efforts are in place for polar bears?",
|
92 |
+
"How can individuals contribute to these efforts?"
|
93 |
+
],
|
94 |
+
"entities": {{
|
95 |
+
"animal": ["polar bears"],
|
96 |
+
"issue": ["climate change"],
|
97 |
+
"actions": ["conservation efforts"]
|
98 |
+
}}
|
99 |
+
}}
|
100 |
+
"""
|
101 |
+
# Assume ai is an initialized MetaAI instance that can send prompts to the AI service
|
102 |
+
advanced_response = ai.prompt(message=analysis_prompt)
|
103 |
+
return advanced_response
|
104 |
|
105 |
def parse_analysis(analysis_message):
|
106 |
try:
|
|
|
152 |
# Run sentiment analysis
|
153 |
df_sentiment = sentiment_analysis(msg)
|
154 |
|
155 |
+
# Fetch advanced analysis
|
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)
|
|
|
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"):
|
177 |
# Display negative sentence locations
|