|
|
import streamlit as st
|
|
|
from sentence_transformers import SentenceTransformer
|
|
|
import joblib
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@st.cache_resource
|
|
|
def load_models():
|
|
|
|
|
|
embedder = SentenceTransformer("sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
|
|
|
|
|
|
|
|
|
classifier = joblib.load("classifier.pkl")
|
|
|
|
|
|
|
|
|
label_encoder = joblib.load("label_encoder.pkl")
|
|
|
|
|
|
return embedder, classifier, label_encoder
|
|
|
|
|
|
|
|
|
embedder, classifier, label_encoder = load_models()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config(page_title="Trademark Class Predictor", page_icon="π")
|
|
|
|
|
|
st.title("π NICE Class Predictor (3, 5, Both)")
|
|
|
|
|
|
description = st.text_area("Enter product description:", height=150)
|
|
|
|
|
|
if st.button("Predict Class"):
|
|
|
if description.strip() == "":
|
|
|
st.warning("β οΈ Please enter a valid description.")
|
|
|
else:
|
|
|
|
|
|
emb = embedder.encode([description])
|
|
|
|
|
|
|
|
|
pred_num = classifier.predict(emb)[0]
|
|
|
|
|
|
|
|
|
pred_label = label_encoder.inverse_transform([pred_num])[0]
|
|
|
|
|
|
|
|
|
st.subheader("Prediction:")
|
|
|
if pred_label == "3_only":
|
|
|
st.success("π§΄ Class 3 β Cosmetics & Cleaning Preparations")
|
|
|
elif pred_label == "5_only":
|
|
|
st.success("π Class 5 β Pharmaceutical & Medical Products")
|
|
|
elif pred_label == "both":
|
|
|
st.success("π Both β Mixed Class 3 + Class 5")
|
|
|
else:
|
|
|
st.error("Unknown label.")
|
|
|
|
|
|
|
|
|
if hasattr(classifier, "predict_proba"):
|
|
|
proba = classifier.predict_proba(emb)[0]
|
|
|
st.write("### Confidence Scores:")
|
|
|
for cls, p in zip(label_encoder.classes_, proba):
|
|
|
st.write(f"- **{cls}**: `{p:.3f}`")
|
|
|
|
|
|
|