Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,9 @@ def call_mistral_api(prompt):
|
|
| 22 |
]
|
| 23 |
}
|
| 24 |
try:
|
|
|
|
| 25 |
response = requests.post(url, headers=headers, json=payload)
|
|
|
|
| 26 |
response.raise_for_status() # Raise an error for bad status codes
|
| 27 |
return response.json()['choices'][0]['message']['content']
|
| 28 |
except requests.exceptions.HTTPError as err:
|
|
@@ -36,27 +38,30 @@ def call_mistral_api(prompt):
|
|
| 36 |
|
| 37 |
# Function to analyze a single requirement
|
| 38 |
def analyze_requirement(requirement):
|
|
|
|
| 39 |
# Detect requirement type
|
| 40 |
type_prompt = f"Classify the following requirement as Functional or Non-Functional:\n\n{requirement}\n\nType:"
|
| 41 |
-
req_type = call_mistral_api(type_prompt)
|
| 42 |
|
| 43 |
# Identify stakeholders
|
| 44 |
stakeholders_prompt = f"Identify the stakeholders for the following requirement:\n\n{requirement}\n\nStakeholders:"
|
| 45 |
-
stakeholders = call_mistral_api(stakeholders_prompt)
|
| 46 |
|
| 47 |
# Classify domain
|
| 48 |
domain_prompt = f"Classify the domain for the following requirement (e.g., Bank, Healthcare, etc.):\n\n{requirement}\n\nDomain:"
|
| 49 |
-
domain = call_mistral_api(domain_prompt)
|
| 50 |
|
| 51 |
# Detect defects
|
| 52 |
defects_prompt = f"""Analyze the following requirement and identify ONLY MAJOR defects (e.g., Ambiguity, Incompleteness, etc.).
|
| 53 |
If the requirement is clear and complete, respond with 'No defects.'
|
| 54 |
Requirement: {requirement}
|
| 55 |
Defects:"""
|
| 56 |
-
|
| 57 |
|
| 58 |
# Rewrite requirement
|
| 59 |
-
rewritten = rewrite_requirement(requirement, defects)
|
|
|
|
|
|
|
| 60 |
|
| 61 |
return {
|
| 62 |
"Requirement": requirement,
|
|
@@ -64,7 +69,8 @@ def analyze_requirement(requirement):
|
|
| 64 |
"Stakeholders": stakeholders,
|
| 65 |
"Domain": domain,
|
| 66 |
"Defects": defects,
|
| 67 |
-
"Rewritten": rewritten
|
|
|
|
| 68 |
}
|
| 69 |
|
| 70 |
# Function to rewrite requirement concisely
|
|
@@ -80,7 +86,7 @@ def rewrite_requirement(requirement, defects):
|
|
| 80 |
Defects: {defects}
|
| 81 |
|
| 82 |
Rewritten Requirement:"""
|
| 83 |
-
response = call_mistral_api(prompt)
|
| 84 |
return response.strip()
|
| 85 |
|
| 86 |
# Function to generate a PDF report with professional formatting
|
|
@@ -164,6 +170,7 @@ def main():
|
|
| 164 |
st.write(f"**Domain:** {result['Domain']}")
|
| 165 |
st.write(f"**Defects:** {result['Defects']}")
|
| 166 |
st.write(f"**Rewritten:** {result['Rewritten']}")
|
|
|
|
| 167 |
st.write("---")
|
| 168 |
|
| 169 |
# Generate and download PDF report
|
|
|
|
| 22 |
]
|
| 23 |
}
|
| 24 |
try:
|
| 25 |
+
start_time = time.time()
|
| 26 |
response = requests.post(url, headers=headers, json=payload)
|
| 27 |
+
latency = round(time.time() - start_time, 2) # in seconds
|
| 28 |
response.raise_for_status() # Raise an error for bad status codes
|
| 29 |
return response.json()['choices'][0]['message']['content']
|
| 30 |
except requests.exceptions.HTTPError as err:
|
|
|
|
| 38 |
|
| 39 |
# Function to analyze a single requirement
|
| 40 |
def analyze_requirement(requirement):
|
| 41 |
+
latencies = {}
|
| 42 |
# Detect requirement type
|
| 43 |
type_prompt = f"Classify the following requirement as Functional or Non-Functional:\n\n{requirement}\n\nType:"
|
| 44 |
+
req_type, latencies["Type"] = call_mistral_api(type_prompt)
|
| 45 |
|
| 46 |
# Identify stakeholders
|
| 47 |
stakeholders_prompt = f"Identify the stakeholders for the following requirement:\n\n{requirement}\n\nStakeholders:"
|
| 48 |
+
stakeholders, latencies["Stakeholders"] = call_mistral_api(stakeholders_prompt)
|
| 49 |
|
| 50 |
# Classify domain
|
| 51 |
domain_prompt = f"Classify the domain for the following requirement (e.g., Bank, Healthcare, etc.):\n\n{requirement}\n\nDomain:"
|
| 52 |
+
domain, latencies["Domain"] = call_mistral_api(domain_prompt)
|
| 53 |
|
| 54 |
# Detect defects
|
| 55 |
defects_prompt = f"""Analyze the following requirement and identify ONLY MAJOR defects (e.g., Ambiguity, Incompleteness, etc.).
|
| 56 |
If the requirement is clear and complete, respond with 'No defects.'
|
| 57 |
Requirement: {requirement}
|
| 58 |
Defects:"""
|
| 59 |
+
defectss, latencies["Defects"] = call_mistral_api(defects_prompt)
|
| 60 |
|
| 61 |
# Rewrite requirement
|
| 62 |
+
rewritten, latencies["Rewritten"] = rewrite_requirement(requirement, defects)
|
| 63 |
+
|
| 64 |
+
total_latency = sum(latencies.values())
|
| 65 |
|
| 66 |
return {
|
| 67 |
"Requirement": requirement,
|
|
|
|
| 69 |
"Stakeholders": stakeholders,
|
| 70 |
"Domain": domain,
|
| 71 |
"Defects": defects,
|
| 72 |
+
"Rewritten": rewritten,
|
| 73 |
+
"Latency (s)": round(total_latency, 2)
|
| 74 |
}
|
| 75 |
|
| 76 |
# Function to rewrite requirement concisely
|
|
|
|
| 86 |
Defects: {defects}
|
| 87 |
|
| 88 |
Rewritten Requirement:"""
|
| 89 |
+
response, latency = call_mistral_api(prompt)
|
| 90 |
return response.strip()
|
| 91 |
|
| 92 |
# Function to generate a PDF report with professional formatting
|
|
|
|
| 170 |
st.write(f"**Domain:** {result['Domain']}")
|
| 171 |
st.write(f"**Defects:** {result['Defects']}")
|
| 172 |
st.write(f"**Rewritten:** {result['Rewritten']}")
|
| 173 |
+
st.write(f"**Total Latency:** {result['Latency (s)']} seconds")
|
| 174 |
st.write("---")
|
| 175 |
|
| 176 |
# Generate and download PDF report
|