MSK34 commited on
Commit
ce63f14
·
verified ·
1 Parent(s): beeb93a

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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)