Update app.py
Browse files
app.py
CHANGED
@@ -61,27 +61,34 @@ def generate_functional_requirements(topic):
|
|
61 |
if generator is None:
|
62 |
return "Error: Model failed to load."
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
74 |
|
75 |
document = "" # Initialize empty document
|
76 |
|
77 |
-
|
78 |
-
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
return document
|
86 |
|
87 |
# 📌 Function to Save Generated Content as PDF
|
@@ -93,7 +100,14 @@ def save_to_pdf(content, filename):
|
|
93 |
text.setLeading(14)
|
94 |
|
95 |
for line in content.split("\n"):
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
text.textLine(line)
|
|
|
97 |
if text.getY() < 50: # Handle page overflow
|
98 |
c.drawText(text)
|
99 |
c.showPage()
|
@@ -130,4 +144,4 @@ def main():
|
|
130 |
os.remove(filename) # Cleanup file after download
|
131 |
|
132 |
if __name__ == "__main__":
|
133 |
-
main()
|
|
|
61 |
if generator is None:
|
62 |
return "Error: Model failed to load."
|
63 |
|
64 |
+
# Structured Sections for Detailed Document
|
65 |
+
sections = [
|
66 |
+
"Introduction: Overview, Purpose, Intended Users",
|
67 |
+
"Scope: System Description, Key Functionalities",
|
68 |
+
"Functional Specifications: Features, User Roles, Transactions",
|
69 |
+
"Security & Compliance: Regulations, Data Protection",
|
70 |
+
"User Interface Requirements: Wireframes, UI/UX Considerations",
|
71 |
+
"System Architecture: High-Level Architecture, Technology Stack",
|
72 |
+
"Performance & Scalability: Expected Load, Response Time, Uptime",
|
73 |
+
"Regulatory & Legal Compliance: Banking Regulations, Audits",
|
74 |
+
"Data Management: Data Flow, Storage, Backup Strategies",
|
75 |
+
"Conclusion: Summary, Future Enhancements"
|
76 |
+
]
|
77 |
|
78 |
document = "" # Initialize empty document
|
79 |
|
80 |
+
# Generate Detailed Content for Each Section
|
81 |
+
for section in sections:
|
82 |
+
prompt = f"Generate a **detailed and structured** section on '{section}' for **{topic}** in banking."
|
83 |
|
84 |
+
for _ in range(3): # Generate more content for each section
|
85 |
+
output = generator(prompt, max_length=2048, do_sample=True, temperature=0.7)
|
86 |
+
|
87 |
+
if output and "generated_text" in output[0]:
|
88 |
+
document += f"### {section}\n\n" + output[0]['generated_text'] + "\n\n"
|
89 |
+
else:
|
90 |
+
return "Error: Model failed to generate text."
|
91 |
+
|
92 |
return document
|
93 |
|
94 |
# 📌 Function to Save Generated Content as PDF
|
|
|
100 |
text.setLeading(14)
|
101 |
|
102 |
for line in content.split("\n"):
|
103 |
+
if "### " in line: # Section Header - Start New Page
|
104 |
+
c.showPage()
|
105 |
+
text = c.beginText(40, 750)
|
106 |
+
text.setLeading(14)
|
107 |
+
c.setFont("Helvetica-Bold", 12)
|
108 |
+
|
109 |
text.textLine(line)
|
110 |
+
|
111 |
if text.getY() < 50: # Handle page overflow
|
112 |
c.drawText(text)
|
113 |
c.showPage()
|
|
|
144 |
os.remove(filename) # Cleanup file after download
|
145 |
|
146 |
if __name__ == "__main__":
|
147 |
+
main()
|