RAHULJUNEJA33's picture
Update app.py
2035c7d verified
import os
import subprocess
# Ensure dependencies are installed
required_packages = ["faker", "streamlit", "python-docx"]
for package in required_packages:
try:
__import__(package)
except ImportError:
subprocess.run(["pip", "install", package])
# Now import modules after installation
from faker import Faker
import streamlit as st
from docx import Document
# Initialize Faker
fake = Faker()
document_types = [
"TL (Trade License)", "MOA (Memorandum of Association)", "Certificate of Incumbency",
"Registration Certificate", "Certificate of Formation", "Certificate of Incorporation",
"Certificate of Incorporation/TL (DED)", "VAT Registration", "Indemnity",
"Address Proof - Shared Desk", "TL (LLC & DIFC)", "Utility Bill", "Ejari",
"Shareholding Doc", "POA (Power of Attorney)", "Good Standing Certificate",
"Incorporation Certificate", "Name Change Certificate", "MOA/TL/Extract/Incumbency",
"Passport", "EID (Emirates ID)", "Visa", "TL/MOA & Certificate of Incumbency/Registration Certificate",
"MOA/BR/POA", "BR/POA", "Mandate/BR"
]
def generate_document(doc_type):
doc = Document()
doc.add_heading(f'{doc_type}', level=1)
doc.add_paragraph(f'Generated on: {fake.date_time_this_year()}')
if "Trade License" in doc_type:
doc.add_paragraph(f'Company Name: {fake.company()}')
doc.add_paragraph(f'Registration Number: {fake.uuid4()}')
doc.add_paragraph(f'Issued Date: {fake.date()}')
doc.add_paragraph(f'Expiry Date: {fake.date()}')
elif "MOA" in doc_type:
doc.add_paragraph(f'Company: {fake.company()}')
doc.add_paragraph(f'Founders: {fake.name()}, {fake.name()}')
doc.add_paragraph(f'Capital: {fake.random_int(10000, 500000)} AED')
doc.add_paragraph(f'Date of Establishment: {fake.date()}')
elif "Certificate" in doc_type:
doc.add_paragraph(f'Business Name: {fake.company()}')
doc.add_paragraph(f'Incorporation Date: {fake.date()}')
doc.add_paragraph(f'Registration ID: {fake.uuid4()}')
elif "VAT Registration" in doc_type:
doc.add_paragraph(f'Company Name: {fake.company()}')
doc.add_paragraph(f'VAT Number: {fake.random_int(100000, 999999)}')
doc.add_paragraph(f'Registration Date: {fake.date()}')
elif "Indemnity" in doc_type:
doc.add_paragraph(f'Indemnified Party: {fake.name()}')
doc.add_paragraph(f'Indemnifier: {fake.name()}')
doc.add_paragraph(f'Agreement Date: {fake.date()}')
elif "Address Proof" in doc_type or "Utility Bill" in doc_type or "Ejari" in doc_type:
doc.add_paragraph(f'Name: {fake.name()}')
doc.add_paragraph(f'Address: {fake.address()}')
doc.add_paragraph(f'Document Date: {fake.date()}')
elif "Shareholding Doc" in doc_type:
doc.add_paragraph(f'Shareholder: {fake.name()}')
doc.add_paragraph(f'Company: {fake.company()}')
doc.add_paragraph(f'Share Percentage: {fake.random_int(1, 100)}%')
elif "POA" in doc_type:
doc.add_paragraph(f'Grantor: {fake.name()}')
doc.add_paragraph(f'Grantee: {fake.name()}')
doc.add_paragraph(f'Authority Granted: Full Business Authority')
elif "Passport" in doc_type or "EID" in doc_type or "Visa" in doc_type:
doc.add_paragraph(f'Name: {fake.name()}')
doc.add_paragraph(f'Document Number: {fake.uuid4()}')
doc.add_paragraph(f'Issue Date: {fake.date()}')
doc.add_paragraph(f'Expiry Date: {fake.date()}')
else:
doc.add_paragraph(f'Generated Placeholder for {doc_type}')
file_name = f"{doc_type.replace(' ', '_')}.docx"
doc.save(file_name)
return file_name
# Streamlit UI
st.title("📄 Document Generator")
st.write("Generate Business and Legal Documents with Synthetic Data")
doc_choice = st.selectbox("Select Document Type:", document_types)
if st.button("Generate Document"):
file_path = generate_document(doc_choice)
with open(file_path, "rb") as file:
st.download_button(label="Download Document", data=file, file_name=file_path, mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
os.remove(file_path)