RAHULJUNEJA33 commited on
Commit
3a754a8
·
verified ·
1 Parent(s): 3ceb495

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ from huggingface_hub import HfApi
3
+ import matplotlib.pyplot as plt
4
+ from docx import Document
5
+ from docx.shared import Inches
6
+
7
+ # Initialize Hugging Face API
8
+ api = HfApi()
9
+
10
+ # Retrieve the API key from Hugging Face Secrets
11
+ OPENAI_API_KEY = api.get_secret("OPENAI_API_KEY")
12
+
13
+ # Configure OpenAI API Key
14
+ openai.api_key = OPENAI_API_KEY
15
+
16
+ def generate_text(prompt):
17
+ """Generate text using OpenAI API"""
18
+ response = openai.ChatCompletion.create(
19
+ model="gpt-4",
20
+ messages=[
21
+ {"role": "system", "content": "You are an expert banking analyst."},
22
+ {"role": "user", "content": prompt}
23
+ ]
24
+ )
25
+ return response["choices"][0]["message"]["content"]
26
+
27
+ # Create a 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
+ # Add System Overview
36
+ doc.add_heading("1. Introduction", level=2)
37
+ intro_text = generate_text("Write an introduction for a banking loan and fraud detection system FSD.")
38
+ doc.add_paragraph(intro_text)
39
+
40
+ # System Architecture Diagram
41
+ doc.add_heading("6. System Architecture Diagram", level=2)
42
+ fig, ax = plt.subplots(figsize=(6, 4))
43
+ ax.text(0.5, 0.85, "Customer", fontsize=12, ha="center", bbox=dict(facecolor="lightblue", edgecolor="black"))
44
+ ax.text(0.5, 0.65, "Banking System", fontsize=12, ha="center", bbox=dict(facecolor="lightgreen", edgecolor="black"))
45
+ ax.text(0.3, 0.45, "Loan Processing", fontsize=12, ha="center", bbox=dict(facecolor="lightyellow", edgecolor="black"))
46
+ ax.text(0.7, 0.45, "Fraud Detection", fontsize=12, ha="center", bbox=dict(facecolor="lightpink", edgecolor="black"))
47
+ ax.text(0.5, 0.25, "Database", fontsize=12, ha="center", bbox=dict(facecolor="lightgray", edgecolor="black"))
48
+
49
+ ax.set_xlim(0, 1)
50
+ ax.set_ylim(0, 1)
51
+ ax.set_xticks([])
52
+ ax.set_yticks([])
53
+ ax.set_frame_on(False)
54
+
55
+ diagram_path = "/mnt/data/banking_system_architecture.png"
56
+ plt.savefig(diagram_path)
57
+ plt.close(fig)
58
+
59
+ doc.add_picture(diagram_path, width=Inches(5))
60
+
61
+ # Save Word Document
62
+ fsd_path = "/mnt/data/Banking_FSD.docx"
63
+ doc.save(fsd_path)
64
+
65
+ print(f"Functional Specification Document (FSD) generated successfully: {fsd_path}")