29 lines
829 B
Python
29 lines
829 B
Python
import streamlit as st
|
|
import joblib
|
|
import re
|
|
|
|
# Load model & vectorizer
|
|
model = joblib.load("model_nb.pkl")
|
|
vectorizer = joblib.load("tfidf_vectorizer.pkl")
|
|
|
|
st.title("📰 Klasifikasi Topik Berita (NLP)")
|
|
st.write("Masukkan teks berita berbahasa Indonesia")
|
|
|
|
text = st.text_area("Teks Berita", height=200)
|
|
|
|
def preprocess_text(text):
|
|
text = text.lower()
|
|
text = re.sub(r"http\S+", "", text)
|
|
text = re.sub(r"[^a-zA-Z\s]", " ", text)
|
|
text = re.sub(r"\s+", " ", text).strip()
|
|
return text
|
|
|
|
if st.button("Klasifikasikan"):
|
|
if text.strip() == "":
|
|
st.warning("Teks tidak boleh kosong!")
|
|
else:
|
|
clean_text = preprocess_text(text)
|
|
text_tfidf = vectorizer.transform([clean_text])
|
|
prediction = model.predict(text_tfidf)[0]
|
|
st.success(f"Prediksi Topik: **{prediction}**")
|