Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import
|
2 |
import requests
|
3 |
from fpdf import FPDF
|
4 |
import pdfplumber
|
@@ -56,28 +56,6 @@ def analyze_requirement(requirement):
|
|
56 |
"Rewritten": rewritten
|
57 |
}
|
58 |
|
59 |
-
# Function to process multiple requirements
|
60 |
-
def process_requirements(input_text, uploaded_file):
|
61 |
-
requirements = []
|
62 |
-
|
63 |
-
# If a file is uploaded, extract text from the PDF
|
64 |
-
if uploaded_file:
|
65 |
-
with pdfplumber.open(uploaded_file) as pdf:
|
66 |
-
for page in pdf.pages:
|
67 |
-
requirements.extend(page.extract_text().split("\n"))
|
68 |
-
|
69 |
-
# If text input is provided, split into individual requirements
|
70 |
-
if input_text:
|
71 |
-
requirements.extend(input_text.split("\n"))
|
72 |
-
|
73 |
-
# Analyze each requirement
|
74 |
-
results = []
|
75 |
-
for req in requirements:
|
76 |
-
if req.strip(): # Ignore empty lines
|
77 |
-
results.append(analyze_requirement(req.strip()))
|
78 |
-
|
79 |
-
return results
|
80 |
-
|
81 |
# Function to generate a PDF report
|
82 |
def generate_pdf_report(results):
|
83 |
pdf = FPDF()
|
@@ -97,46 +75,58 @@ def generate_pdf_report(results):
|
|
97 |
pdf.output(pdf_output)
|
98 |
return pdf_output
|
99 |
|
100 |
-
#
|
101 |
-
def
|
102 |
-
|
103 |
-
|
|
|
104 |
|
105 |
-
#
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
""
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
)
|
140 |
-
|
141 |
-
#
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
import requests
|
3 |
from fpdf import FPDF
|
4 |
import pdfplumber
|
|
|
56 |
"Rewritten": rewritten
|
57 |
}
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# Function to generate a PDF report
|
60 |
def generate_pdf_report(results):
|
61 |
pdf = FPDF()
|
|
|
75 |
pdf.output(pdf_output)
|
76 |
return pdf_output
|
77 |
|
78 |
+
# Streamlit app
|
79 |
+
def main():
|
80 |
+
st.title("Requirement Defects Detective Tool")
|
81 |
+
st.markdown("**Team Name:** Sadia, Areeba, Rabbia, Tesmia")
|
82 |
+
st.markdown("**LLM Model:** Mistral")
|
83 |
|
84 |
+
# Input options
|
85 |
+
input_option = st.radio("Choose input method:", ("Enter Requirements", "Upload PDF"))
|
86 |
+
|
87 |
+
requirements = []
|
88 |
+
if input_option == "Enter Requirements":
|
89 |
+
input_text = st.text_area("Enter your requirements (one per line):")
|
90 |
+
if input_text:
|
91 |
+
requirements = input_text.split("\n")
|
92 |
+
else:
|
93 |
+
uploaded_file = st.file_uploader("Upload a PDF file:", type="pdf")
|
94 |
+
if uploaded_file:
|
95 |
+
with pdfplumber.open(uploaded_file) as pdf:
|
96 |
+
for page in pdf.pages:
|
97 |
+
requirements.extend(page.extract_text().split("\n"))
|
98 |
+
|
99 |
+
# Analyze requirements
|
100 |
+
if st.button("Analyze Requirements"):
|
101 |
+
if not requirements:
|
102 |
+
st.warning("Please enter or upload requirements.")
|
103 |
+
else:
|
104 |
+
results = []
|
105 |
+
for req in requirements:
|
106 |
+
if req.strip(): # Ignore empty lines
|
107 |
+
results.append(analyze_requirement(req.strip()))
|
108 |
+
|
109 |
+
# Display results
|
110 |
+
st.subheader("Analysis Results")
|
111 |
+
for result in results:
|
112 |
+
st.write(f"**Requirement:** {result['Requirement']}")
|
113 |
+
st.write(f"**Type:** {result['Type']}")
|
114 |
+
st.write(f"**Stakeholders:** {result['Stakeholders']}")
|
115 |
+
st.write(f"**Domain:** {result['Domain']}")
|
116 |
+
st.write(f"**Defects:** {result['Defects']}")
|
117 |
+
st.write(f"**Rewritten:** {result['Rewritten']}")
|
118 |
+
st.write("---")
|
119 |
+
|
120 |
+
# Generate and download PDF report
|
121 |
+
pdf_report = generate_pdf_report(results)
|
122 |
+
with open(pdf_report, "rb") as f:
|
123 |
+
st.download_button(
|
124 |
+
label="Download PDF Report",
|
125 |
+
data=f,
|
126 |
+
file_name="requirements_report.pdf",
|
127 |
+
mime="application/pdf"
|
128 |
+
)
|
129 |
+
|
130 |
+
# Run the app
|
131 |
+
if __name__ == "__main__":
|
132 |
+
main()
|