Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -227,28 +227,31 @@ def generate_pdf_report(result, charts=None, table_data=None, metadata=None, key
|
|
227 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_pdf:
|
228 |
pdf = FPDF()
|
229 |
pdf.add_page()
|
230 |
-
|
|
|
|
|
|
|
231 |
pdf.set_auto_page_break(auto=True, margin=15)
|
232 |
|
233 |
-
pdf.set_font("
|
234 |
pdf.cell(200, 10, txt="Patent Strategy and Innovation Report", ln=True, align="C")
|
235 |
pdf.ln(10)
|
236 |
|
237 |
if metadata:
|
238 |
-
pdf.set_font("
|
239 |
for key, value in metadata.items():
|
240 |
pdf.cell(200, 10, txt=f"{key}: {value}", ln=True)
|
241 |
|
242 |
-
pdf.set_font("
|
243 |
pdf.multi_cell(0, 10, txt=result)
|
244 |
|
245 |
# Insert Key Insights Section
|
246 |
if key_insights:
|
247 |
pdf.add_page()
|
248 |
-
pdf.set_font("
|
249 |
pdf.cell(200, 10, txt="Key Strategic Insights", ln=True)
|
250 |
pdf.ln(5)
|
251 |
-
pdf.set_font("
|
252 |
for insight in key_insights:
|
253 |
pdf.multi_cell(0, 10, txt=f"- {insight}")
|
254 |
|
@@ -264,7 +267,7 @@ def generate_pdf_report(result, charts=None, table_data=None, metadata=None, key
|
|
264 |
# Insert Tables
|
265 |
if table_data:
|
266 |
pdf.add_page()
|
267 |
-
pdf.set_font("
|
268 |
pdf.cell(200, 10, txt="Consolidated Data Table:", ln=True, align="L")
|
269 |
for row in table_data:
|
270 |
pdf.cell(200, 10, txt=str(row), ln=True)
|
@@ -272,7 +275,6 @@ def generate_pdf_report(result, charts=None, table_data=None, metadata=None, key
|
|
272 |
pdf.output(temp_pdf.name)
|
273 |
return temp_pdf.name
|
274 |
|
275 |
-
|
276 |
# Data Validation
|
277 |
def validate_analyst_output(analyst_output):
|
278 |
if not analyst_output:
|
@@ -345,8 +347,6 @@ def create_visualizations(analyst_output):
|
|
345 |
|
346 |
return chart_paths
|
347 |
|
348 |
-
|
349 |
-
|
350 |
def display_table(analyst_output):
|
351 |
table_data = []
|
352 |
validated_data = validate_analyst_output(analyst_output)
|
|
|
227 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_pdf:
|
228 |
pdf = FPDF()
|
229 |
pdf.add_page()
|
230 |
+
|
231 |
+
# Add a Unicode-compatible font (DejaVuSans)
|
232 |
+
pdf.add_font('DejaVu', '', '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', uni=True)
|
233 |
+
pdf.set_font("DejaVu", size=12)
|
234 |
pdf.set_auto_page_break(auto=True, margin=15)
|
235 |
|
236 |
+
pdf.set_font("DejaVu", size=16, style="B")
|
237 |
pdf.cell(200, 10, txt="Patent Strategy and Innovation Report", ln=True, align="C")
|
238 |
pdf.ln(10)
|
239 |
|
240 |
if metadata:
|
241 |
+
pdf.set_font("DejaVu", size=10)
|
242 |
for key, value in metadata.items():
|
243 |
pdf.cell(200, 10, txt=f"{key}: {value}", ln=True)
|
244 |
|
245 |
+
pdf.set_font("DejaVu", size=12)
|
246 |
pdf.multi_cell(0, 10, txt=result)
|
247 |
|
248 |
# Insert Key Insights Section
|
249 |
if key_insights:
|
250 |
pdf.add_page()
|
251 |
+
pdf.set_font("DejaVu", size=14, style="B")
|
252 |
pdf.cell(200, 10, txt="Key Strategic Insights", ln=True)
|
253 |
pdf.ln(5)
|
254 |
+
pdf.set_font("DejaVu", size=12)
|
255 |
for insight in key_insights:
|
256 |
pdf.multi_cell(0, 10, txt=f"- {insight}")
|
257 |
|
|
|
267 |
# Insert Tables
|
268 |
if table_data:
|
269 |
pdf.add_page()
|
270 |
+
pdf.set_font("DejaVu", size=10)
|
271 |
pdf.cell(200, 10, txt="Consolidated Data Table:", ln=True, align="L")
|
272 |
for row in table_data:
|
273 |
pdf.cell(200, 10, txt=str(row), ln=True)
|
|
|
275 |
pdf.output(temp_pdf.name)
|
276 |
return temp_pdf.name
|
277 |
|
|
|
278 |
# Data Validation
|
279 |
def validate_analyst_output(analyst_output):
|
280 |
if not analyst_output:
|
|
|
347 |
|
348 |
return chart_paths
|
349 |
|
|
|
|
|
350 |
def display_table(analyst_output):
|
351 |
table_data = []
|
352 |
validated_data = validate_analyst_output(analyst_output)
|