arittrabag commited on
Commit
62fbd69
Β·
verified Β·
1 Parent(s): 64b7c25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -11,6 +11,21 @@ import pandas as pd
11
  import streamlit as st
12
  from num2words import num2words
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Try to import Playwright for PDF conversion
15
  PLAYWRIGHT_AVAILABLE = False
16
 
@@ -44,7 +59,7 @@ def format_amount(x):
44
  num = float(x)
45
  if num == 0:
46
  return "0.00"
47
- return f"{num:,.2f}"
48
  except Exception:
49
  return "0.00"
50
 
@@ -295,7 +310,7 @@ if __name__ == "__main__":
295
 
296
  if result.returncode == 0 and os.path.exists(pdf_path):
297
  return True
298
- else:
299
  print(f"Subprocess approach failed: {result.stderr}")
300
 
301
  except Exception as e2:
@@ -330,7 +345,7 @@ def extract_first_page_pdf(input_pdf_path: str, output_pdf_path: str) -> bool:
330
  reader = PdfReader(input_pdf_path)
331
 
332
  # Create a new PDF writer
333
- writer = PdfWriter()
334
 
335
  # Add only the first page (if it exists)
336
  if len(reader.pages) > 0:
@@ -515,7 +530,7 @@ with col2:
515
 
516
  # Processing section
517
  if template_file:
518
- st.markdown("---")
519
  st.subheader("πŸš€ Generate Invoices")
520
 
521
  col3, col4 = st.columns(2)
@@ -529,8 +544,8 @@ if template_file:
529
  help="Select Inephos template to enable this button"):
530
  if not data_file:
531
  st.error("Please upload customer data file.")
532
- else:
533
- with st.spinner("Generating Inephos invoices..."):
534
  try:
535
  zip_buffer, count = process_invoices_html(data_file, "inephos.html", "inephos")
536
  st.success(f"βœ… Generated {count} Inephos invoices successfully!")
@@ -556,8 +571,8 @@ if template_file:
556
  help="Select Srestham template to enable this button"):
557
  if not data_file:
558
  st.error("Please upload customer data file.")
559
- else:
560
- with st.spinner("Generating Srestham invoices..."):
561
  try:
562
  zip_buffer, count = process_invoices_html(data_file, "srestham.html", "srestham")
563
  st.success(f"βœ… Generated {count} Srestham invoices successfully!")
 
11
  import streamlit as st
12
  from num2words import num2words
13
 
14
+ # Install Playwright browsers on first run (for Hugging Face Spaces)
15
+ import subprocess
16
+ import sys
17
+
18
+ if not os.path.exists('/tmp/playwright_installed'):
19
+ try:
20
+ print("πŸ”§ Installing Playwright browsers...")
21
+ subprocess.run([sys.executable, "-m", "playwright", "install", "chromium"], check=True)
22
+ with open('/tmp/playwright_installed', 'w') as f:
23
+ f.write('installed')
24
+ print("βœ… Playwright browsers installed!")
25
+ except Exception as e:
26
+ print(f"⚠️ Failed to install Playwright browsers: {e}")
27
+ print("App will continue but PDF generation may not work")
28
+
29
  # Try to import Playwright for PDF conversion
30
  PLAYWRIGHT_AVAILABLE = False
31
 
 
59
  num = float(x)
60
  if num == 0:
61
  return "0.00"
62
+ return f"{num:,.2f}"
63
  except Exception:
64
  return "0.00"
65
 
 
310
 
311
  if result.returncode == 0 and os.path.exists(pdf_path):
312
  return True
313
+ else:
314
  print(f"Subprocess approach failed: {result.stderr}")
315
 
316
  except Exception as e2:
 
345
  reader = PdfReader(input_pdf_path)
346
 
347
  # Create a new PDF writer
348
+ writer = PdfWriter()
349
 
350
  # Add only the first page (if it exists)
351
  if len(reader.pages) > 0:
 
530
 
531
  # Processing section
532
  if template_file:
533
+ st.markdown("---")
534
  st.subheader("πŸš€ Generate Invoices")
535
 
536
  col3, col4 = st.columns(2)
 
544
  help="Select Inephos template to enable this button"):
545
  if not data_file:
546
  st.error("Please upload customer data file.")
547
+ else:
548
+ with st.spinner("Generating Inephos invoices..."):
549
  try:
550
  zip_buffer, count = process_invoices_html(data_file, "inephos.html", "inephos")
551
  st.success(f"βœ… Generated {count} Inephos invoices successfully!")
 
571
  help="Select Srestham template to enable this button"):
572
  if not data_file:
573
  st.error("Please upload customer data file.")
574
+ else:
575
+ with st.spinner("Generating Srestham invoices..."):
576
  try:
577
  zip_buffer, count = process_invoices_html(data_file, "srestham.html", "srestham")
578
  st.success(f"βœ… Generated {count} Srestham invoices successfully!")