Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,16 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
from fpdf import FPDF
|
| 4 |
import pdfplumber
|
|
|
|
| 5 |
|
| 6 |
-
# Mistral API key (replace with your key)
|
| 7 |
-
|
| 8 |
-
MISTRAL_API_URL = "https://api.mistral.ai/v1/chat/completions"
|
| 9 |
|
| 10 |
# Function to call Mistral API
|
| 11 |
def call_mistral_api(prompt):
|
|
|
|
| 12 |
headers = {
|
| 13 |
-
"Authorization": f"Bearer {
|
| 14 |
"Content-Type": "application/json"
|
| 15 |
}
|
| 16 |
payload = {
|
|
@@ -19,11 +20,14 @@ def call_mistral_api(prompt):
|
|
| 19 |
{"role": "user", "content": prompt}
|
| 20 |
]
|
| 21 |
}
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
return response.json()['choices'][0]['message']['content']
|
| 25 |
-
|
| 26 |
-
return f"Error: {
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Function to analyze a single requirement
|
| 29 |
def analyze_requirement(requirement):
|
|
@@ -40,7 +44,10 @@ def analyze_requirement(requirement):
|
|
| 40 |
domain = call_mistral_api(domain_prompt)
|
| 41 |
|
| 42 |
# Detect defects
|
| 43 |
-
defects_prompt = f"
|
|
|
|
|
|
|
|
|
|
| 44 |
defects = call_mistral_api(defects_prompt)
|
| 45 |
|
| 46 |
# Rewrite requirement
|
|
@@ -77,9 +84,9 @@ def generate_pdf_report(results):
|
|
| 77 |
|
| 78 |
# Streamlit app
|
| 79 |
def main():
|
| 80 |
-
st.title("Requirement
|
| 81 |
-
st.markdown("**Team Name:**
|
| 82 |
-
st.markdown("**
|
| 83 |
|
| 84 |
# Input options
|
| 85 |
input_option = st.radio("Choose input method:", ("Enter Requirements", "Upload PDF"))
|
|
|
|
| 2 |
import requests
|
| 3 |
from fpdf import FPDF
|
| 4 |
import pdfplumber
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
# Mistral API key (replace with your key or use environment variable)
|
| 8 |
+
api_key = os.getenv("MISTRAL_API_KEY", "gz6lDXokxgR6cLY72oomALWcm7vhjRzQ")
|
|
|
|
| 9 |
|
| 10 |
# Function to call Mistral API
|
| 11 |
def call_mistral_api(prompt):
|
| 12 |
+
url = "https://api.mistral.ai/v1/chat/completions"
|
| 13 |
headers = {
|
| 14 |
+
"Authorization": f"Bearer {api_key}",
|
| 15 |
"Content-Type": "application/json"
|
| 16 |
}
|
| 17 |
payload = {
|
|
|
|
| 20 |
{"role": "user", "content": prompt}
|
| 21 |
]
|
| 22 |
}
|
| 23 |
+
try:
|
| 24 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 25 |
+
response.raise_for_status() # Raise an error for bad status codes
|
| 26 |
return response.json()['choices'][0]['message']['content']
|
| 27 |
+
except requests.exceptions.HTTPError as err:
|
| 28 |
+
return f"HTTP Error: {err}"
|
| 29 |
+
except Exception as err:
|
| 30 |
+
return f"Error: {err}"
|
| 31 |
|
| 32 |
# Function to analyze a single requirement
|
| 33 |
def analyze_requirement(requirement):
|
|
|
|
| 44 |
domain = call_mistral_api(domain_prompt)
|
| 45 |
|
| 46 |
# Detect defects
|
| 47 |
+
defects_prompt = f"""Analyze the following requirement and identify ONLY MAJOR defects (e.g., Ambiguity, Incompleteness, etc.).
|
| 48 |
+
If the requirement is clear and complete, respond with 'No defects.'
|
| 49 |
+
Requirement: {requirement}
|
| 50 |
+
Defects:"""
|
| 51 |
defects = call_mistral_api(defects_prompt)
|
| 52 |
|
| 53 |
# Rewrite requirement
|
|
|
|
| 84 |
|
| 85 |
# Streamlit app
|
| 86 |
def main():
|
| 87 |
+
st.title("Requirement Analysis Tool")
|
| 88 |
+
st.markdown("**Team Name:** Team Innovators")
|
| 89 |
+
st.markdown("**Model:** Mistral")
|
| 90 |
|
| 91 |
# Input options
|
| 92 |
input_option = st.radio("Choose input method:", ("Enter Requirements", "Upload PDF"))
|