Upload files to "/"
This commit is contained in:
commit
4103cc9d04
28
app.py
Normal file
28
app.py
Normal file
@ -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}**")
|
||||
Loading…
x
Reference in New Issue
Block a user