DrishtiSharma commited on
Commit
f24a07b
·
verified ·
1 Parent(s): f8436e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -116,8 +116,8 @@ write = Task(
116
  analyse = Task(
117
  description=(
118
  "1. Perform statistical analysis of patent filing trends, innovation hot spots, and growth projections.\n"
119
- "2. Collaborate with the Planner and Writer to align on data needs.\n"
120
- "3. Present findings in an actionable format."
121
  ),
122
  expected_output="A detailed statistical analysis with actionable insights for stakeholders.",
123
  agent=analyst
@@ -154,16 +154,30 @@ def create_visualizations(analyst_output):
154
  """Create visualizations for advanced insights."""
155
  if enable_custom_visualization and analyst_output:
156
  try:
157
- data = pd.DataFrame(analyst_output)
158
- if 'Category' in data.columns and 'Values' in data.columns:
159
- st.markdown("### Advanced Visualization")
160
- fig = px.bar(data, x="Category", y="Values", title="Patent Trends by Category")
161
- st.plotly_chart(fig)
 
 
 
 
162
  else:
163
- st.warning("Data does not have the required columns for visualization.")
164
  except Exception as e:
165
  st.error(f"Failed to create visualizations: {e}")
166
 
 
 
 
 
 
 
 
 
 
 
167
  if st.button("Generate Patent Insights"):
168
  with st.spinner('Processing...'):
169
  try:
@@ -199,6 +213,9 @@ if st.button("Generate Patent Insights"):
199
  if enable_advanced_analysis:
200
  create_visualizations(analyst_output)
201
 
 
 
 
202
  # Display Token Usage and Execution Time
203
  st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
204
  token_usage = getattr(results, "token_usage", None)
@@ -213,4 +230,4 @@ if st.button("Generate Patent Insights"):
213
  st.download_button("Download Report", data=report_file, file_name="Patent_Report.pdf")
214
 
215
  except Exception as e:
216
- st.error(f"An error occurred during execution: {e}")
 
116
  analyse = Task(
117
  description=(
118
  "1. Perform statistical analysis of patent filing trends, innovation hot spots, and growth projections.\n"
119
+ "2. Provide structured output with fields 'Category' and 'Values' for visualization.\n"
120
+ "3. Collaborate with the Planner and Writer to align on data needs."
121
  ),
122
  expected_output="A detailed statistical analysis with actionable insights for stakeholders.",
123
  agent=analyst
 
154
  """Create visualizations for advanced insights."""
155
  if enable_custom_visualization and analyst_output:
156
  try:
157
+ # Validate and format analyst output
158
+ if isinstance(analyst_output, list) and all(isinstance(item, dict) for item in analyst_output):
159
+ data = pd.DataFrame(analyst_output)
160
+ if 'Category' in data.columns and 'Values' in data.columns:
161
+ st.markdown("### Advanced Visualization")
162
+ fig = px.bar(data, x="Category", y="Values", title="Patent Trends by Category")
163
+ st.plotly_chart(fig)
164
+ else:
165
+ st.warning("Data does not have the required columns 'Category' and 'Values'.")
166
  else:
167
+ st.warning("Analyst output is not in the correct format for visualization.")
168
  except Exception as e:
169
  st.error(f"Failed to create visualizations: {e}")
170
 
171
+ def display_table(analyst_output):
172
+ """Display tabular data for detailed insights."""
173
+ if analyst_output and isinstance(analyst_output, list):
174
+ try:
175
+ data = pd.DataFrame(analyst_output)
176
+ st.markdown("### Data Table")
177
+ st.dataframe(data)
178
+ except Exception as e:
179
+ st.error(f"Failed to display table: {e}")
180
+
181
  if st.button("Generate Patent Insights"):
182
  with st.spinner('Processing...'):
183
  try:
 
213
  if enable_advanced_analysis:
214
  create_visualizations(analyst_output)
215
 
216
+ # Display tabular data
217
+ display_table(analyst_output)
218
+
219
  # Display Token Usage and Execution Time
220
  st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
221
  token_usage = getattr(results, "token_usage", None)
 
230
  st.download_button("Download Report", data=report_file, file_name="Patent_Report.pdf")
231
 
232
  except Exception as e:
233
+ st.error(f"An error occurred during execution: {e}")