File size: 1,236 Bytes
323a079
 
 
 
 
 
bfab49a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import streamlit as st
import pandas as pd
import json

from utils.preprocess import preprocess_text
from utils.predict import load_model, predict_label

st.set_page_config(
    page_title="BRD Clarity Detection",
    layout="wide"
)

st.title("📄 BRD Clarity Detection Tool")

@st.cache_resource
def init_model():
    clf, s2v = load_model()
    return clf, s2v

clf, s2v_model = init_model()

uploaded_file = st.file_uploader(
    "Upload requirement file (JSON or TXT)",
    type=["json", "txt"]
)

text_input = st.text_area("Or paste requirement text here", height=200)

if st.button("Analyze"):
    if uploaded_file:
        if uploaded_file.name.endswith(".json"):
            data = json.load(uploaded_file)
            texts = [d["text"] for d in data]
        else:
            texts = uploaded_file.read().decode("utf-8").splitlines()
    elif text_input.strip():
        texts = text_input.splitlines()
    else:
        st.warning("Please upload a file or paste text")
        st.stop()

    df = pd.DataFrame({"text": texts})
    df["clean_text"] = df["text"].apply(preprocess_text)

    preds = predict_label(df["clean_text"], clf, s2v_model)
    df["Prediction"] = preds

    st.dataframe(df, use_container_width=True)