Spaces:
Sleeping
Sleeping
DrishtiSharma
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,10 @@ import pandas as pd
|
|
8 |
import plotly.express as px
|
9 |
import tempfile
|
10 |
import time
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Title and Application Introduction
|
13 |
st.title("Patent Strategy and Innovation Consultant")
|
@@ -152,8 +156,9 @@ def generate_pdf_report(result, charts=None, table_data=None, metadata=None):
|
|
152 |
try:
|
153 |
pdf.add_page()
|
154 |
pdf.image(chart_path, x=10, y=20, w=180)
|
|
|
155 |
except Exception as e:
|
156 |
-
|
157 |
|
158 |
if table_data:
|
159 |
pdf.add_page()
|
@@ -186,6 +191,9 @@ def create_visualizations(analyst_output):
|
|
186 |
if validated_data:
|
187 |
data = pd.DataFrame(validated_data)
|
188 |
try:
|
|
|
|
|
|
|
189 |
bar_chart = px.bar(data, x="Category", y="Values", title="Patent Trends by Category")
|
190 |
st.plotly_chart(bar_chart)
|
191 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_chart:
|
@@ -211,6 +219,7 @@ def create_visualizations(analyst_output):
|
|
211 |
chart_paths.append(temp_chart.name)
|
212 |
|
213 |
except Exception as e:
|
|
|
214 |
st.error(f"Error generating visualization: {e}")
|
215 |
return chart_paths
|
216 |
|
@@ -261,4 +270,5 @@ if st.button("Generate Patent Insights"):
|
|
261 |
st.download_button("Download Report", data=report_file, file_name="Patent_Strategy_Report.pdf")
|
262 |
|
263 |
except Exception as e:
|
264 |
-
|
|
|
|
8 |
import plotly.express as px
|
9 |
import tempfile
|
10 |
import time
|
11 |
+
import logging
|
12 |
+
|
13 |
+
# Setup logging
|
14 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
15 |
|
16 |
# Title and Application Introduction
|
17 |
st.title("Patent Strategy and Innovation Consultant")
|
|
|
156 |
try:
|
157 |
pdf.add_page()
|
158 |
pdf.image(chart_path, x=10, y=20, w=180)
|
159 |
+
logging.info(f"Successfully included chart: {chart_path}")
|
160 |
except Exception as e:
|
161 |
+
logging.error(f"Failed to include chart in PDF: {chart_path}. Error: {e}")
|
162 |
|
163 |
if table_data:
|
164 |
pdf.add_page()
|
|
|
191 |
if validated_data:
|
192 |
data = pd.DataFrame(validated_data)
|
193 |
try:
|
194 |
+
if data.empty:
|
195 |
+
raise ValueError("Data for visualizations is empty.")
|
196 |
+
|
197 |
bar_chart = px.bar(data, x="Category", y="Values", title="Patent Trends by Category")
|
198 |
st.plotly_chart(bar_chart)
|
199 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_chart:
|
|
|
219 |
chart_paths.append(temp_chart.name)
|
220 |
|
221 |
except Exception as e:
|
222 |
+
logging.error(f"Error generating visualization: {e}")
|
223 |
st.error(f"Error generating visualization: {e}")
|
224 |
return chart_paths
|
225 |
|
|
|
270 |
st.download_button("Download Report", data=report_file, file_name="Patent_Strategy_Report.pdf")
|
271 |
|
272 |
except Exception as e:
|
273 |
+
logging.error(f"An error occurred during execution: {e}")
|
274 |
+
st.error(f"An error occurred during execution: {e}")
|