Update src/streamlit_app.py
Browse files- src/streamlit_app.py +61 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,62 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import joblib
|
| 4 |
+
import re
|
| 5 |
+
from nltk.corpus import stopwords
|
| 6 |
+
import nltk
|
| 7 |
+
|
| 8 |
+
nltk.download("stopwords")
|
| 9 |
+
|
| 10 |
+
st.set_page_config(
|
| 11 |
+
page_title="Disaster Tweet Classification",
|
| 12 |
+
page_icon="🚨",
|
| 13 |
+
layout="centered"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
stop_words = set(stopwords.words("english"))
|
| 17 |
+
|
| 18 |
+
def temizle(text):
|
| 19 |
+
text = text.lower()
|
| 20 |
+
text = re.sub(r"http\S+", " ", text)
|
| 21 |
+
text = re.sub(r"www\S+", " ", text)
|
| 22 |
+
text = re.sub(r"@\w+", " ", text)
|
| 23 |
+
text = re.sub(r"&", " ", text)
|
| 24 |
+
text = re.sub(r"rt", " ", text)
|
| 25 |
+
text = re.sub(r"[^a-z\s]", " ", text)
|
| 26 |
+
|
| 27 |
+
kelimeler = [
|
| 28 |
+
kelime for kelime in text.split()
|
| 29 |
+
if kelime not in stop_words
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
return " ".join(kelimeler)
|
| 33 |
+
|
| 34 |
+
model = joblib.load("src/disaster_tweet_model.pkl")
|
| 35 |
+
tfidf = joblib.load("src/tfidf_vectorizer.pkl")
|
| 36 |
+
|
| 37 |
+
st.title("🚨 Afet Tweet Sınıflandırma Uygulaması")
|
| 38 |
+
|
| 39 |
+
st.write(
|
| 40 |
+
"Bu uygulama, girilen bir tweet metninin gerçek bir afet olayıyla ilgili olup olmadığını tahmin eder."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
tweet = st.text_area(
|
| 44 |
+
"Tweet metnini giriniz:",
|
| 45 |
+
placeholder="Örnek: Forest fire near La Ronge Sask. Canada"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
if st.button("Tahmin Et"):
|
| 49 |
+
if tweet.strip() == "":
|
| 50 |
+
st.warning("Lütfen bir tweet metni giriniz.")
|
| 51 |
+
else:
|
| 52 |
+
clean_tweet = temizle(tweet)
|
| 53 |
+
tweet_tfidf = tfidf.transform([clean_tweet])
|
| 54 |
+
prediction = model.predict(tweet_tfidf)[0]
|
| 55 |
+
|
| 56 |
+
if prediction == 1:
|
| 57 |
+
st.error("Sonuç: Bu tweet gerçek bir afetle ilgili olabilir.")
|
| 58 |
+
else:
|
| 59 |
+
st.success("Sonuç: Bu tweet gerçek bir afetle ilgili görünmüyor.")
|
| 60 |
+
|
| 61 |
+
st.write("Temizlenmiş metin:")
|
| 62 |
+
st.info(clean_tweet)
|