RAHULJUNEJA33 commited on
Commit
3c8efae
Β·
verified Β·
1 Parent(s): db496d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -1
app.py CHANGED
@@ -1 +1,66 @@
1
- Document (FSD) generated successfully: {fsd_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import matplotlib.pyplot as plt
3
+ from docx import Document
4
+ from docx.shared import Inches
5
+ from huggingface_hub import get_secret_value # Import secret retrieval function
6
+
7
+ # βœ… Retrieve API key securely from Hugging Face secret store
8
+ try:
9
+ OPENAI_API_KEY = get_secret_value("OPENAI_API_KEY") # Fetch stored API key
10
+ except Exception as e:
11
+ raise RuntimeError("Failed to retrieve OpenAI API Key from Hugging Face Secrets.") from e
12
+
13
+ # βœ… Configure OpenAI API Key
14
+ openai.api_key = OPENAI_API_KEY
15
+
16
+ def generate_text(prompt):
17
+ """Generate text using OpenAI GPT securely"""
18
+ response = openai.ChatCompletion.create(
19
+ model="gpt-4",
20
+ messages=[
21
+ {"role": "system", "content": "You are a banking expert creating an FSD."},
22
+ {"role": "user", "content": prompt}
23
+ ]
24
+ )
25
+ return response["choices"][0]["message"]["content"]
26
+
27
+ # βœ… Create Word Document
28
+ doc = Document()
29
+ doc.add_heading('Functional Specification Document (FSD)', level=1)
30
+ doc.add_paragraph("**Project Name:** Banking Loan & Fraud Detection System")
31
+ doc.add_paragraph("**Version:** 1.0")
32
+ doc.add_paragraph("**Prepared By:** Your Name")
33
+ doc.add_paragraph("**Date:** DD/MM/YYYY")
34
+
35
+ # βœ… Generate FSD Content
36
+ doc.add_page_break()
37
+ doc.add_heading("1. Introduction", level=2)
38
+ intro_text = generate_text("Write a detailed introduction for a banking loan and fraud detection system FSD.")
39
+ doc.add_paragraph(intro_text)
40
+
41
+ # βœ… Add System Architecture Diagram
42
+ doc.add_heading("6. System Architecture Diagram", level=2)
43
+ fig, ax = plt.subplots(figsize=(6, 4))
44
+ ax.text(0.5, 0.85, "Customer", fontsize=12, ha="center", bbox=dict(facecolor="lightblue", edgecolor="black"))
45
+ ax.text(0.5, 0.65, "Banking System", fontsize=12, ha="center", bbox=dict(facecolor="lightgreen", edgecolor="black"))
46
+ ax.text(0.3, 0.45, "Loan Processing", fontsize=12, ha="center", bbox=dict(facecolor="lightyellow", edgecolor="black"))
47
+ ax.text(0.7, 0.45, "Fraud Detection", fontsize=12, ha="center", bbox=dict(facecolor="lightpink", edgecolor="black"))
48
+ ax.text(0.5, 0.25, "Database", fontsize=12, ha="center", bbox=dict(facecolor="lightgray", edgecolor="black"))
49
+
50
+ ax.set_xlim(0, 1)
51
+ ax.set_ylim(0, 1)
52
+ ax.set_xticks([])
53
+ ax.set_yticks([])
54
+ ax.set_frame_on(False)
55
+
56
+ diagram_path = "/mnt/data/banking_system_architecture.png"
57
+ plt.savefig(diagram_path)
58
+ plt.close(fig)
59
+
60
+ doc.add_picture(diagram_path, width=Inches(5))
61
+
62
+ # βœ… Save the Word Document
63
+ fsd_path = "/mnt/data/Banking_FSD.docx"
64
+ doc.save(fsd_path)
65
+
66
+ print(f"βœ… Functional Specification Document (FSD) generated successfully: {fsd_path}")