Create app2.py
Browse files
app2.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Load Hugging Face Token from Environment (Set this in Hugging Face Spaces Secrets)
|
| 6 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
+
|
| 8 |
+
# Select model: Use a quantized, smaller model like DistilGPT-2
|
| 9 |
+
MODEL_NAME = "distilgpt2" # Change to any of the small models mentioned above
|
| 10 |
+
|
| 11 |
+
# Load Model
|
| 12 |
+
@st.cache_resource
|
| 13 |
+
def load_model():
|
| 14 |
+
try:
|
| 15 |
+
return pipeline("text-generation", model=MODEL_NAME, token=HF_TOKEN)
|
| 16 |
+
except Exception as e:
|
| 17 |
+
st.error(f"❌ Error loading model: {str(e)}")
|
| 18 |
+
return None
|
| 19 |
+
|
| 20 |
+
generator = load_model()
|
| 21 |
+
|
| 22 |
+
# Function to Generate Functional Requirement Document
|
| 23 |
+
def generate_functional_requirements(topic):
|
| 24 |
+
if generator is None:
|
| 25 |
+
return "Error: Model not loaded properly."
|
| 26 |
+
|
| 27 |
+
prompt = f"Generate a comprehensive functional requirement document for {topic} in the banking sector."
|
| 28 |
+
|
| 29 |
+
# Generate content
|
| 30 |
+
output = generator(prompt, max_length=800, do_sample=True, temperature=0.8)
|
| 31 |
+
return output[0]['generated_text']
|
| 32 |
+
|
| 33 |
+
# Streamlit UI
|
| 34 |
+
def main():
|
| 35 |
+
st.title("📄 AI-Powered Functional Requirement Generator for Banking")
|
| 36 |
+
|
| 37 |
+
banking_topics = [
|
| 38 |
+
"Core Banking System",
|
| 39 |
+
"Loan Management System",
|
| 40 |
+
"Payment Processing Gateway",
|
| 41 |
+
"Risk and Fraud Detection",
|
| 42 |
+
"Regulatory Compliance Management",
|
| 43 |
+
"Digital Banking APIs",
|
| 44 |
+
"Customer Onboarding & KYC",
|
| 45 |
+
"Treasury Management",
|
| 46 |
+
"Wealth & Portfolio Management"
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
topic = st.selectbox("Select a Banking Functional Requirement Topic", banking_topics)
|
| 50 |
+
|
| 51 |
+
if st.button("Generate Functional Requirement Document"):
|
| 52 |
+
with st.spinner("Generating... This may take a while."):
|
| 53 |
+
content = generate_functional_requirements(topic)
|
| 54 |
+
if "Error" in content:
|
| 55 |
+
st.error(content)
|
| 56 |
+
else:
|
| 57 |
+
filename = "functional_requirement.pdf"
|
| 58 |
+
save_to_pdf(content, filename)
|
| 59 |
+
st.success("✅ Functional Requirement Document Generated!")
|
| 60 |
+
st.download_button(label="📥 Download PDF", data=open(filename, "rb"), file_name=filename, mime="application/pdf")
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
main()
|