Spaces:
No application file
No application file
Update streamlit_app.py
Browse files- streamlit_app.py +42 -6
streamlit_app.py
CHANGED
|
@@ -1,12 +1,48 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
|
| 4 |
-
ROOT_DIR = Path(__file__).resolve().parent
|
| 5 |
-
sys.path.append(str(ROOT_DIR))
|
| 6 |
-
|
| 7 |
import streamlit as st
|
| 8 |
import pandas as pd
|
| 9 |
import json
|
| 10 |
|
| 11 |
from utils.preprocess import preprocess_text
|
| 12 |
from utils.predict import load_model, predict_label
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
|
| 5 |
from utils.preprocess import preprocess_text
|
| 6 |
from utils.predict import load_model, predict_label
|
| 7 |
+
|
| 8 |
+
st.set_page_config(
|
| 9 |
+
page_title="BRD Clarity Detection",
|
| 10 |
+
layout="wide"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
st.title("📄 BRD Clarity Detection Tool")
|
| 14 |
+
|
| 15 |
+
@st.cache_resource
|
| 16 |
+
def init_model():
|
| 17 |
+
clf, s2v = load_model()
|
| 18 |
+
return clf, s2v
|
| 19 |
+
|
| 20 |
+
clf, s2v_model = init_model()
|
| 21 |
+
|
| 22 |
+
uploaded_file = st.file_uploader(
|
| 23 |
+
"Upload requirement file (JSON or TXT)",
|
| 24 |
+
type=["json", "txt"]
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
text_input = st.text_area("Or paste requirement text here", height=200)
|
| 28 |
+
|
| 29 |
+
if st.button("Analyze"):
|
| 30 |
+
if uploaded_file:
|
| 31 |
+
if uploaded_file.name.endswith(".json"):
|
| 32 |
+
data = json.load(uploaded_file)
|
| 33 |
+
texts = [d["text"] for d in data]
|
| 34 |
+
else:
|
| 35 |
+
texts = uploaded_file.read().decode("utf-8").splitlines()
|
| 36 |
+
elif text_input.strip():
|
| 37 |
+
texts = text_input.splitlines()
|
| 38 |
+
else:
|
| 39 |
+
st.warning("Please upload a file or paste text")
|
| 40 |
+
st.stop()
|
| 41 |
+
|
| 42 |
+
df = pd.DataFrame({"text": texts})
|
| 43 |
+
df["clean_text"] = df["text"].apply(preprocess_text)
|
| 44 |
+
|
| 45 |
+
preds = predict_label(df["clean_text"], clf, s2v_model)
|
| 46 |
+
df["Prediction"] = preds
|
| 47 |
+
|
| 48 |
+
st.dataframe(df, use_container_width=True)
|