RAHULJUNEJA33 commited on
Commit
ac492b0
·
verified ·
1 Parent(s): 9ecdd44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -26
app.py CHANGED
@@ -1,28 +1,35 @@
1
- import openai # OpenAI API for GenAI-generated text
 
2
  import matplotlib.pyplot as plt
3
  from docx import Document
4
  from docx.shared import Inches
5
-
6
- # Set your OpenAI API Key
7
- OPENAI_API_KEY = "your-openai-api-key"
8
-
9
- def generate_text(prompt):
10
- """Generate text using OpenAI API"""
11
- response = openai.ChatCompletion.create(
12
- model="gpt-4",
13
- messages=[{"role": "system", "content": "You are an expert banking analyst."},
14
- {"role": "user", "content": prompt}],
15
- api_key=OPENAI_API_KEY
16
- )
17
- return response["choices"][0]["message"]["content"]
18
-
19
- # Create a Word document
 
 
 
 
 
 
20
  doc = Document()
21
  doc.add_heading('Functional Specification Document (FSD)', level=1)
22
  doc.add_paragraph("**Project Name:** Banking Loan & Fraud Detection System")
23
  doc.add_paragraph("**Version:** 1.0")
24
  doc.add_paragraph("**Prepared By:** Your Name")
25
- doc.add_paragraph("**Date:** DD/MM/YYYY")
26
 
27
  # Table of Contents
28
  doc.add_page_break()
@@ -60,6 +67,11 @@ doc.add_heading("3. Functional Requirements", level=2)
60
  functional_reqs = generate_text("List functional requirements for a banking fraud detection and loan system.")
61
  doc.add_paragraph(functional_reqs)
62
 
 
 
 
 
 
63
  # Security & Compliance
64
  doc.add_heading("5. Security & Compliance", level=2)
65
  security_text = generate_text("What are the security and compliance requirements for a banking loan system?")
@@ -68,11 +80,16 @@ doc.add_paragraph(security_text)
68
  # Generate System Architecture Diagram
69
  doc.add_heading("6. System Architecture Diagram", level=2)
70
  fig, ax = plt.subplots(figsize=(6, 4))
71
- ax.text(0.5, 0.85, "Customer", fontsize=12, ha="center", bbox=dict(facecolor="lightblue", edgecolor="black"))
72
- ax.text(0.5, 0.65, "Banking System", fontsize=12, ha="center", bbox=dict(facecolor="lightgreen", edgecolor="black"))
73
- ax.text(0.3, 0.45, "Loan Processing", fontsize=12, ha="center", bbox=dict(facecolor="lightyellow", edgecolor="black"))
74
- ax.text(0.7, 0.45, "Fraud Detection", fontsize=12, ha="center", bbox=dict(facecolor="lightpink", edgecolor="black"))
75
- ax.text(0.5, 0.25, "Database", fontsize=12, ha="center", bbox=dict(facecolor="lightgray", edgecolor="black"))
 
 
 
 
 
76
 
77
  ax.set_xlim(0, 1)
78
  ax.set_ylim(0, 1)
@@ -80,8 +97,10 @@ ax.set_xticks([])
80
  ax.set_yticks([])
81
  ax.set_frame_on(False)
82
 
83
- # Save diagram
84
- diagram_path = "banking_system_architecture.png"
 
 
85
  plt.savefig(diagram_path)
86
  plt.close(fig)
87
 
@@ -96,7 +115,31 @@ doc.add_paragraph("(*Placeholder for detailed banking process flow diagrams*)")
96
  doc.add_heading("8. UI Mockups", level=2)
97
  doc.add_paragraph("(*Placeholder for UI Mockups for loan applications, fraud alerts, and account dashboards*)")
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  # Save the Word Document
100
- doc.save("Banking_FSD.docx")
 
101
 
102
- print("Functional Specification Document (FSD) generated successfully as 'Banking_FSD.docx'")
 
1
+ import os
2
+ import openai
3
  import matplotlib.pyplot as plt
4
  from docx import Document
5
  from docx.shared import Inches
6
+ from datetime import datetime
7
+
8
+ # Set your OpenAI API Key securely using environment variables
9
+ openai.api_key = os.getenv("OPENAI_API_KEY")
10
+
11
+ def generate_text(prompt, role="user"):
12
+ """Generate text using the new OpenAI API format."""
13
+ try:
14
+ response = openai.ChatCompletion.acreate(
15
+ model="gpt-4",
16
+ messages=[
17
+ {"role": "system", "content": "You are an expert banking analyst."},
18
+ {"role": role, "content": prompt}
19
+ ]
20
+ )
21
+ return response['choices'][0]['message']['content']
22
+ except Exception as e:
23
+ print(f"Error generating text: {e}")
24
+ return "(*Failed to generate content. Please review manually.*)"
25
+
26
+ # Create the Word document
27
  doc = Document()
28
  doc.add_heading('Functional Specification Document (FSD)', level=1)
29
  doc.add_paragraph("**Project Name:** Banking Loan & Fraud Detection System")
30
  doc.add_paragraph("**Version:** 1.0")
31
  doc.add_paragraph("**Prepared By:** Your Name")
32
+ doc.add_paragraph(f"**Date:** {datetime.now().strftime('%d/%m/%Y')}")
33
 
34
  # Table of Contents
35
  doc.add_page_break()
 
67
  functional_reqs = generate_text("List functional requirements for a banking fraud detection and loan system.")
68
  doc.add_paragraph(functional_reqs)
69
 
70
+ # Non-Functional Requirements
71
+ doc.add_heading("4. Non-Functional Requirements", level=2)
72
+ non_functional_reqs = generate_text("List non-functional requirements for a banking loan and fraud detection system.")
73
+ doc.add_paragraph(non_functional_reqs)
74
+
75
  # Security & Compliance
76
  doc.add_heading("5. Security & Compliance", level=2)
77
  security_text = generate_text("What are the security and compliance requirements for a banking loan system?")
 
80
  # Generate System Architecture Diagram
81
  doc.add_heading("6. System Architecture Diagram", level=2)
82
  fig, ax = plt.subplots(figsize=(6, 4))
83
+ ax.text(0.5, 0.85, "Customer", fontsize=12, ha="center",
84
+ bbox=dict(facecolor="lightblue", edgecolor="black"))
85
+ ax.text(0.5, 0.65, "Banking System", fontsize=12, ha="center",
86
+ bbox=dict(facecolor="lightgreen", edgecolor="black"))
87
+ ax.text(0.3, 0.45, "Loan Processing", fontsize=12, ha="center",
88
+ bbox=dict(facecolor="lightyellow", edgecolor="black"))
89
+ ax.text(0.7, 0.45, "Fraud Detection", fontsize=12, ha="center",
90
+ bbox=dict(facecolor="lightpink", edgecolor="black"))
91
+ ax.text(0.5, 0.25, "Database", fontsize=12, ha="center",
92
+ bbox=dict(facecolor="lightgray", edgecolor="black"))
93
 
94
  ax.set_xlim(0, 1)
95
  ax.set_ylim(0, 1)
 
97
  ax.set_yticks([])
98
  ax.set_frame_on(False)
99
 
100
+ # Save diagram in a designated output folder
101
+ output_folder = "output"
102
+ os.makedirs(output_folder, exist_ok=True)
103
+ diagram_path = os.path.join(output_folder, "banking_system_architecture.png")
104
  plt.savefig(diagram_path)
105
  plt.close(fig)
106
 
 
115
  doc.add_heading("8. UI Mockups", level=2)
116
  doc.add_paragraph("(*Placeholder for UI Mockups for loan applications, fraud alerts, and account dashboards*)")
117
 
118
+ # Assumptions and Constraints
119
+ doc.add_heading("9. Assumptions and Constraints", level=2)
120
+ assumptions_text = generate_text("List assumptions and constraints for a banking loan and fraud detection system.")
121
+ doc.add_paragraph(assumptions_text)
122
+
123
+ # Dependencies
124
+ doc.add_heading("10. Dependencies", level=2)
125
+ dependencies_text = generate_text("List the dependencies for a banking loan and fraud detection system project.")
126
+ doc.add_paragraph(dependencies_text)
127
+
128
+ # Acceptance Criteria
129
+ doc.add_heading("11. Acceptance Criteria", level=2)
130
+ acceptance_criteria = generate_text("Define acceptance criteria for a banking loan and fraud detection system.")
131
+ doc.add_paragraph(acceptance_criteria)
132
+
133
+ # Glossary
134
+ doc.add_heading("12. Glossary", level=2)
135
+ doc.add_paragraph("(*Placeholder for glossary of terms related to banking, loans, and fraud detection*)")
136
+
137
+ # References
138
+ doc.add_heading("13. References", level=2)
139
+ doc.add_paragraph("(*Placeholder for references including documents, articles, and regulatory guidelines*)")
140
+
141
  # Save the Word Document
142
+ doc_path = os.path.join(output_folder, "Banking_FSD.docx")
143
+ doc.save(doc_path)
144
 
145
+ print(f"Functional Specification Document (FSD) generated successfully at: {doc_path}")