commit 4103cc9d043502d833d80d1c602dbd05b06e0953 Author: 202210715213 MONA DEWINTHA AGUSTINE <202210715213@mhs.ubharajaya.ac.id> Date: Thu Jan 22 10:03:24 2026 +0700 Upload files to "/" diff --git a/app.py b/app.py new file mode 100644 index 0000000..9a5cb12 --- /dev/null +++ b/app.py @@ -0,0 +1,28 @@ +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}**")