| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| MODEL_NAME = "google/flan-t5-base" |
|
|
| |
| |
| |
| import streamlit as st |
| from transformers import pipeline |
| from reportlab.lib.pagesizes import letter |
| from reportlab.pdfgen import canvas |
| import os |
| import textwrap |
|
|
| |
| HF_TOKEN = os.getenv("HF_TOKEN") |
|
|
| |
| MODEL_NAME = "google/flan-t5-base" |
|
|
| |
| @st.cache_resource |
| def load_model(): |
| try: |
| return pipeline("text2text-generation", model=MODEL_NAME, token=HF_TOKEN) |
| except Exception as e: |
| st.error(f"β Error loading model: {str(e)}") |
| return None |
|
|
| |
| generator = load_model() |
|
|
| |
| def generate_functional_requirements(topic): |
| if generator is None: |
| return "Error: Model failed to load." |
|
|
| sections = [ |
| "Introduction: Overview, Purpose, Intended Users", |
| "Scope: System Description, Key Functionalities", |
| "Functional Specifications: Features, User Roles, Transactions", |
| "Security & Compliance: Regulations, Data Protection", |
| "User Interface Requirements: Wireframes, UI/UX Considerations", |
| "System Architecture: High-Level Architecture, Technology Stack", |
| "Performance & Scalability: Expected Load, Response Time, Uptime", |
| "Regulatory & Legal Compliance: Banking Regulations, Audits", |
| "Data Management: Data Flow, Storage, Backup Strategies", |
| "Conclusion: Summary, Future Enhancements" |
| ] |
|
|
| document = "" |
| for section in sections: |
| prompt = f"Generate a **detailed and structured** section on '{section}' for **{topic}** in banking." |
| |
| for _ in range(3): |
| output = generator(prompt, max_length=2048, do_sample=True, temperature=0.7) |
|
|
| if output and isinstance(output, list) and len(output) > 0 and "generated_text" in output[0]: |
| document += f"\n\n### {section}\n\n" + output[0]["generated_text"] + "\n\n" |
| else: |
| return "Error: Model failed to generate text." |
|
|
| return document |
|
|
| |
| def save_to_pdf(content, filename): |
| if not content.strip(): |
| st.error("β Error: No content available to write to the PDF.") |
| return |
|
|
| c = canvas.Canvas(filename, pagesize=letter) |
| c.setFont("Helvetica", 10) |
|
|
| |
| max_width = 80 |
| lines_per_page = 50 |
| y_position = 750 |
|
|
| paragraphs = content.split("\n\n") |
|
|
| for para in paragraphs: |
| wrapped_lines = textwrap.wrap(para, max_width) |
|
|
| for line in wrapped_lines: |
| if y_position < 50: |
| c.showPage() |
| c.setFont("Helvetica", 10) |
| y_position = 750 |
|
|
| c.drawString(40, y_position, line) |
| y_position -= 14 |
|
|
| c.save() |
|
|
| |
| def main(): |
| st.title("π AI-Powered Functional Requirement Generator for Banking") |
| |
| banking_topics = [ |
| "Core Banking System", "Loan Management System", "Payment Processing Gateway", |
| "Risk and Fraud Detection", "Regulatory Compliance Management", "Digital Banking APIs", |
| "Customer Onboarding & KYC", "Treasury Management", "Wealth & Portfolio Management" |
| ] |
| |
| topic = st.selectbox("Select a Banking Functional Requirement Topic", banking_topics) |
| |
| if st.button("Generate Functional Requirement Document"): |
| with st.spinner("Generating... This may take a while."): |
| content = generate_functional_requirements(topic) |
|
|
| if "Error" in content: |
| st.error(content) |
| else: |
| |
| st.text_area("Generated Document Preview", content[:5000], height=400) |
|
|
| filename = "functional_requirement.pdf" |
| save_to_pdf(content, filename) |
| |
| st.success("β
Document Generated Successfully!") |
| st.download_button("π₯ Download PDF", data=open(filename, "rb"), file_name=filename, mime="application/pdf") |
| os.remove(filename) |
|
|
| if __name__ == "__main__": |
| main() |