Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ import markdown2
|
|
| 13 |
import re
|
| 14 |
import json
|
| 15 |
import os
|
|
|
|
| 16 |
|
| 17 |
# Configure Gemini API
|
| 18 |
gemini_api_key = os.environ.get('GOOGLE_API_KEY')
|
|
@@ -335,7 +336,7 @@ def main():
|
|
| 335 |
|
| 336 |
# Generate report
|
| 337 |
prompt = f"""
|
| 338 |
-
Analyze this business data and generate a comprehensive report in plain text format.
|
| 339 |
|
| 340 |
Data:
|
| 341 |
{json.dumps(json_data, indent=2)}
|
|
@@ -345,8 +346,24 @@ def main():
|
|
| 345 |
response = model.generate_content(prompt)
|
| 346 |
report = response.text
|
| 347 |
st.markdown(report)
|
|
|
|
|
|
|
| 348 |
# PDF Generation and display
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
else:
|
| 351 |
st.error("No data available for reports")
|
| 352 |
|
|
|
|
| 13 |
import re
|
| 14 |
import json
|
| 15 |
import os
|
| 16 |
+
from markdown_pdf import MarkdownPdf, Section
|
| 17 |
|
| 18 |
# Configure Gemini API
|
| 19 |
gemini_api_key = os.environ.get('GOOGLE_API_KEY')
|
|
|
|
| 336 |
|
| 337 |
# Generate report
|
| 338 |
prompt = f"""
|
| 339 |
+
Analyze this business data and generate a comprehensive report in plain text format. Use markdown for headings and structure. Do not include any json.
|
| 340 |
|
| 341 |
Data:
|
| 342 |
{json.dumps(json_data, indent=2)}
|
|
|
|
| 346 |
response = model.generate_content(prompt)
|
| 347 |
report = response.text
|
| 348 |
st.markdown(report)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
# PDF Generation and display
|
| 352 |
+
try:
|
| 353 |
+
pdf = MarkdownPdf()
|
| 354 |
+
pdf.meta["title"] = 'Surburb Business Report'
|
| 355 |
+
pdf.add_section(Section(Report, toc=False))
|
| 356 |
+
pdf.save('report.pdf')
|
| 357 |
+
st.download_button(
|
| 358 |
+
label="Download Report as PDF",
|
| 359 |
+
data=pdf_bytes,
|
| 360 |
+
file_name="report.pdf",
|
| 361 |
+
mime="application/pdf"
|
| 362 |
+
)
|
| 363 |
+
st.markdown(report) # Display the report below the download button
|
| 364 |
+
except Exception as e:
|
| 365 |
+
st.error(f"Error generating PDF: {e}")
|
| 366 |
+
st.markdown(report)
|
| 367 |
else:
|
| 368 |
st.error("No data available for reports")
|
| 369 |
|