RAHULJUNEJA33 commited on
Commit
9ecdd44
Β·
verified Β·
1 Parent(s): 59d9105

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -44
app.py CHANGED
@@ -1,44 +1,22 @@
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 huggingface_hub import HfApi
7
-
8
- # βœ… Retrieve API key securely from Hugging Face secret store (using environment variables)
9
- def retrieve_openai_api_key():
10
- """Retrieve OpenAI API Key securely from Hugging Face Secrets storage."""
11
- # Fetch the API Key using the Hugging Face API
12
- api = HfApi()
13
- try:
14
- openai_api_key = api.get_secret("OPENAI_API_KEY") # Fetch API key from Hugging Face Secrets
15
- if openai_api_key is None:
16
- raise ValueError("OPENAI API Key not found in Hugging Face Secrets.")
17
- return openai_api_key
18
- except Exception as e:
19
- raise RuntimeError(f"Error retrieving OpenAI API Key: {str(e)}") from e
20
-
21
- # βœ… Retrieve API key from Hugging Face secret store
22
- OPENAI_API_KEY = retrieve_openai_api_key()
23
-
24
- # βœ… Configure OpenAI API Key
25
- openai.api_key = OPENAI_API_KEY
26
 
27
  def generate_text(prompt):
28
- """Generate text using OpenAI GPT securely"""
29
- try:
30
- response = openai.ChatCompletion.create(
31
- model="gpt-4",
32
- messages=[
33
- {"role": "system", "content": "You are a banking expert creating an FSD."},
34
- {"role": "user", "content": prompt}
35
- ]
36
- )
37
- return response["choices"][0]["message"]["content"]
38
- except Exception as e:
39
- raise RuntimeError(f"Error generating content with OpenAI API: {str(e)}") from e
40
-
41
- # βœ… Create Word Document
42
  doc = Document()
43
  doc.add_heading('Functional Specification Document (FSD)', level=1)
44
  doc.add_paragraph("**Project Name:** Banking Loan & Fraud Detection System")
@@ -46,13 +24,48 @@ doc.add_paragraph("**Version:** 1.0")
46
  doc.add_paragraph("**Prepared By:** Your Name")
47
  doc.add_paragraph("**Date:** DD/MM/YYYY")
48
 
49
- # βœ… Generate FSD Content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  doc.add_page_break()
51
  doc.add_heading("1. Introduction", level=2)
52
- intro_text = generate_text("Write a detailed introduction for a banking loan and fraud detection system FSD.")
53
  doc.add_paragraph(intro_text)
54
 
55
- # βœ… Add System Architecture Diagram
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  doc.add_heading("6. System Architecture Diagram", level=2)
57
  fig, ax = plt.subplots(figsize=(6, 4))
58
  ax.text(0.5, 0.85, "Customer", fontsize=12, ha="center", bbox=dict(facecolor="lightblue", edgecolor="black"))
@@ -67,14 +80,23 @@ ax.set_xticks([])
67
  ax.set_yticks([])
68
  ax.set_frame_on(False)
69
 
70
- diagram_path = "/mnt/data/banking_system_architecture.png"
 
71
  plt.savefig(diagram_path)
72
  plt.close(fig)
73
 
 
74
  doc.add_picture(diagram_path, width=Inches(5))
75
 
76
- # βœ… Save the Word Document
77
- fsd_path = "/mnt/data/Banking_FSD.docx"
78
- doc.save(fsd_path)
 
 
 
 
 
 
 
79
 
80
- print(f"βœ… Functional Specification Document (FSD) generated successfully: {fsd_path}")
 
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")
 
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()
29
+ doc.add_heading("Table of Contents", level=2)
30
+ toc = [
31
+ "1. Introduction",
32
+ "2. System Overview",
33
+ "3. Functional Requirements",
34
+ "4. Non-Functional Requirements",
35
+ "5. Security & Compliance",
36
+ "6. System Architecture Diagram",
37
+ "7. Process Flow Diagrams",
38
+ "8. UI Mockups",
39
+ "9. Assumptions and Constraints",
40
+ "10. Dependencies",
41
+ "11. Acceptance Criteria",
42
+ "12. Glossary",
43
+ "13. References"
44
+ ]
45
+ for item in toc:
46
+ doc.add_paragraph(item)
47
+
48
+ # Generate Content Using AI
49
  doc.add_page_break()
50
  doc.add_heading("1. Introduction", level=2)
51
+ intro_text = generate_text("Write an introduction for a banking loan and fraud detection system FSD.")
52
  doc.add_paragraph(intro_text)
53
 
54
+ doc.add_heading("2. System Overview", level=2)
55
+ overview_text = generate_text("Write a detailed system overview of a banking fraud detection and loan system.")
56
+ doc.add_paragraph(overview_text)
57
+
58
+ # Functional Requirements
59
+ 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?")
66
+ doc.add_paragraph(security_text)
67
+
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"))
 
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
 
88
+ # Insert diagram
89
  doc.add_picture(diagram_path, width=Inches(5))
90
 
91
+ # Process Flow Diagrams
92
+ doc.add_heading("7. Process Flow Diagrams", level=2)
93
+ doc.add_paragraph("(*Placeholder for detailed banking process flow diagrams*)")
94
+
95
+ # UI Mockups
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'")