Update app.py
Browse files
app.py
CHANGED
|
@@ -6,17 +6,15 @@ import time
|
|
| 6 |
|
| 7 |
# Constants for file paths and MIME types
|
| 8 |
PDF_MIME_TYPE = "application/pdf"
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Ensure directories exist
|
| 20 |
os.makedirs(PRODUCT_IMAGES_DIR, exist_ok=True)
|
| 21 |
os.makedirs(COMPETITOR_IMAGES_DIR, exist_ok=True)
|
| 22 |
|
|
@@ -92,7 +90,7 @@ if st.button("Generate"):
|
|
| 92 |
st.session_state.analysis_in_progress = True # mark as in progress
|
| 93 |
st.subheader("Product Images vs Competitor Images")
|
| 94 |
|
| 95 |
-
#
|
| 96 |
for idx, img_file in enumerate(product_images):
|
| 97 |
img = Image.open(img_file)
|
| 98 |
if img.mode == "RGBA":
|
|
@@ -110,8 +108,8 @@ if st.button("Generate"):
|
|
| 110 |
with open(STATUS_FILE, "w") as f:
|
| 111 |
f.write("pending")
|
| 112 |
|
| 113 |
-
#
|
| 114 |
-
subprocess.Popen(['python', 'src/analysis.py', company_name
|
| 115 |
|
| 116 |
# Monitor the status file
|
| 117 |
st.info("Running analysis. Please wait...")
|
|
@@ -121,7 +119,7 @@ if st.button("Generate"):
|
|
| 121 |
st.success("Analysis completed successfully!")
|
| 122 |
st.session_state.report_generated = True # mark as generated
|
| 123 |
|
| 124 |
-
#
|
| 125 |
for report_name, label in [
|
| 126 |
(BRAND_MARKETING, f"{company_name} Brand Marketing Report"),
|
| 127 |
(CONTENT_MARKETING, f"{company_name} Content Marketing Report"),
|
|
@@ -138,8 +136,8 @@ if st.button("Generate"):
|
|
| 138 |
else:
|
| 139 |
st.error(f"{report_name} not found. Please generate the report first.")
|
| 140 |
|
| 141 |
-
#
|
| 142 |
-
custom_report_name = f"
|
| 143 |
if os.path.exists(REPORT):
|
| 144 |
with open(REPORT, "rb") as report_file:
|
| 145 |
st.download_button(
|
|
|
|
| 6 |
|
| 7 |
# Constants for file paths and MIME types
|
| 8 |
PDF_MIME_TYPE = "application/pdf"
|
| 9 |
+
BRAND_MARKETING = "data/reports/template_PDF/brand marketing.pdf"
|
| 10 |
+
CONTENT_MARKETING = "data/reports/template_PDF/content marketing.pdf"
|
| 11 |
+
SOCIAL_MEDIA_MARKETING = "data/reports/template_PDF/social media marketing.pdf"
|
| 12 |
+
PRODUCT_IMAGES_DIR = "data/product"
|
| 13 |
+
COMPETITOR_IMAGES_DIR = "data/competitor"
|
| 14 |
+
REPORT = "src/Report/report.pdf"
|
| 15 |
+
STATUS_FILE = "src/Report/status.txt" # Path to the status file
|
| 16 |
+
|
| 17 |
+
# Ensure directories for saving images exist
|
|
|
|
|
|
|
| 18 |
os.makedirs(PRODUCT_IMAGES_DIR, exist_ok=True)
|
| 19 |
os.makedirs(COMPETITOR_IMAGES_DIR, exist_ok=True)
|
| 20 |
|
|
|
|
| 90 |
st.session_state.analysis_in_progress = True # mark as in progress
|
| 91 |
st.subheader("Product Images vs Competitor Images")
|
| 92 |
|
| 93 |
+
# Save images to respective directories
|
| 94 |
for idx, img_file in enumerate(product_images):
|
| 95 |
img = Image.open(img_file)
|
| 96 |
if img.mode == "RGBA":
|
|
|
|
| 108 |
with open(STATUS_FILE, "w") as f:
|
| 109 |
f.write("pending")
|
| 110 |
|
| 111 |
+
# Execute the analysis script asynchronously
|
| 112 |
+
subprocess.Popen(['python', 'src/analysis.py', company_name])
|
| 113 |
|
| 114 |
# Monitor the status file
|
| 115 |
st.info("Running analysis. Please wait...")
|
|
|
|
| 119 |
st.success("Analysis completed successfully!")
|
| 120 |
st.session_state.report_generated = True # mark as generated
|
| 121 |
|
| 122 |
+
# Download Buttons for Generated PDF Reports
|
| 123 |
for report_name, label in [
|
| 124 |
(BRAND_MARKETING, f"{company_name} Brand Marketing Report"),
|
| 125 |
(CONTENT_MARKETING, f"{company_name} Content Marketing Report"),
|
|
|
|
| 136 |
else:
|
| 137 |
st.error(f"{report_name} not found. Please generate the report first.")
|
| 138 |
|
| 139 |
+
# For the custom report
|
| 140 |
+
custom_report_name = f"{company_name} report.pdf"
|
| 141 |
if os.path.exists(REPORT):
|
| 142 |
with open(REPORT, "rb") as report_file:
|
| 143 |
st.download_button(
|