Update app.py
Browse files
app.py
CHANGED
@@ -55,44 +55,56 @@ def call_groq_api(prompt):
|
|
55 |
|
56 |
# Function to analyze a single requirement
|
57 |
def analyze_requirement(requirement):
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
defects = [
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
# Function to generate a PDF report
|
97 |
def generate_pdf_report(results):
|
98 |
pdf = FPDF()
|
|
|
55 |
|
56 |
# Function to analyze a single requirement
|
57 |
def analyze_requirement(requirement):
|
58 |
+
try:
|
59 |
+
# 1. Classify requirement type
|
60 |
+
type_prompt = f"Classify this requirement as Functional or Non-Functional (one word only):\n{requirement}"
|
61 |
+
req_type = call_mistral_api(type_prompt).strip()
|
62 |
+
|
63 |
+
# 2. Identify domain
|
64 |
+
domain_prompt = f"Identify the domain for this requirement (one word only, e.g., Healthcare, Finance):\n{requirement}"
|
65 |
+
domain = call_mistral_api(domain_prompt).strip()
|
66 |
+
|
67 |
+
# 3. Detect defects
|
68 |
+
defects_prompt = f"""List ONLY the major defects in this requirement
|
69 |
+
(EXACTLY 3 bullet points, each defect 1-2 words maximum):
|
70 |
+
- Defect1
|
71 |
+
- Defect2
|
72 |
+
- Defect3
|
73 |
+
|
74 |
+
Requirement: {requirement}
|
75 |
+
Defects:"""
|
76 |
+
defects_response = call_groq_api(defects_prompt).strip()
|
77 |
+
|
78 |
+
# Process defects
|
79 |
+
defects = []
|
80 |
+
if "API Error" not in defects_response:
|
81 |
+
defects = [line.strip()[2:] for line in defects_response.split("\n")
|
82 |
+
if line.strip().startswith("- ")]
|
83 |
+
if not defects:
|
84 |
+
defects = ["No major defects found"]
|
85 |
+
|
86 |
+
# 4. Rewrite requirement
|
87 |
+
rewrite_prompt = f"""Rewrite this requirement to fix defects while keeping it concise
|
88 |
+
(1-2 sentences maximum):\n{requirement}"""
|
89 |
+
rewritten = call_groq_api(rewrite_prompt).strip()
|
90 |
+
|
91 |
+
return {
|
92 |
+
"Requirement": requirement,
|
93 |
+
"Type": req_type if "HTTP Error" not in req_type else "Unknown",
|
94 |
+
"Domain": domain if "HTTP Error" not in domain else "Unknown",
|
95 |
+
"Defects": defects,
|
96 |
+
"Rewritten": rewritten if "HTTP Error" not in rewritten else requirement
|
97 |
+
}
|
98 |
+
|
99 |
+
except Exception as e:
|
100 |
+
st.error(f"Analysis failed: {str(e)}")
|
101 |
+
return {
|
102 |
+
"Requirement": requirement,
|
103 |
+
"Type": "Error",
|
104 |
+
"Domain": "Error",
|
105 |
+
"Defects": ["Analysis Failed"],
|
106 |
+
"Rewritten": requirement
|
107 |
+
}
|
108 |
# Function to generate a PDF report
|
109 |
def generate_pdf_report(results):
|
110 |
pdf = FPDF()
|