Sanket17 commited on
Commit
285f427
Β·
verified Β·
1 Parent(s): 9c2adb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
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
- # βœ… Store temporary files in /tmp/ (Hugging Face safe storage)
11
- PRODUCT_IMAGES_DIR = "/tmp/product"
12
- COMPETITOR_IMAGES_DIR = "/tmp/competitor"
13
- REPORT = "/tmp/report.pdf"
14
- STATUS_FILE = "/tmp/status.txt"
15
- BRAND_MARKETING = "/tmp/brand_marketing.pdf"
16
- CONTENT_MARKETING = "/tmp/content_marketing.pdf"
17
- SOCIAL_MEDIA_MARKETING = "/tmp/social_media_marketing.pdf"
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
- # βœ… Save images to /tmp/ (cloud-safe location)
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
- # βœ… Execute analysis script with /tmp/ directory
114
- subprocess.Popen(['python', 'src/analysis.py', company_name, "/tmp/"])
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
- # βœ… Provide Download Buttons for Generated PDF Reports
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
- # βœ… Provide Download for the Final Report
142
- custom_report_name = f"/tmp/{company_name}_report.pdf"
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(