Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +51 -0
- disaster_model.pkl +3 -0
- requirements.txt +6 -0
- tfidf_vectorizer.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from keras.models import load_model # type: ignore
|
4 |
+
import joblib
|
5 |
+
import nltk
|
6 |
+
import pickle
|
7 |
+
from nltk.corpus import stopwords
|
8 |
+
from nltk.tokenize import word_tokenize
|
9 |
+
from nltk.stem import WordNetLemmatizer
|
10 |
+
import re
|
11 |
+
|
12 |
+
# Modeli ve TF-IDF vectorizer'ı yükle
|
13 |
+
with open('disaster_model.pkl', 'rb') as f:
|
14 |
+
model = pickle.load(f)
|
15 |
+
vectorizer = joblib.load("tfidf_vectorizer.pkl")
|
16 |
+
|
17 |
+
# NLTK paketlerini indir
|
18 |
+
nltk.download('stopwords')
|
19 |
+
nltk.download('punkt')
|
20 |
+
nltk.download('wordnet')
|
21 |
+
|
22 |
+
# Preprocessing fonksiyonları
|
23 |
+
stop_words = set(stopwords.words('english'))
|
24 |
+
lemmatizer = WordNetLemmatizer()
|
25 |
+
|
26 |
+
def preprocess_text(text):
|
27 |
+
text = text.lower()
|
28 |
+
text = re.sub(r'[^\w\s]', '', text)
|
29 |
+
text = re.sub(r'\s+', ' ', text)
|
30 |
+
text = re.sub(r'\d+', ' ', text)
|
31 |
+
tokens = word_tokenize(text)
|
32 |
+
tokens = [lemmatizer.lemmatize(word) for word in tokens if word not in stop_words]
|
33 |
+
return ' '.join(tokens)
|
34 |
+
|
35 |
+
def predict_sentiment(text):
|
36 |
+
text = preprocess_text(text)
|
37 |
+
text_vectorized = vectorizer.transform([text]).toarray()
|
38 |
+
prediction = model.predict(text_vectorized)
|
39 |
+
return 'Real Disaster' if prediction > 0.5 else 'Not Real Disaster'
|
40 |
+
|
41 |
+
# Gradio arayüzü
|
42 |
+
demo = gr.Interface(
|
43 |
+
fn=predict_sentiment,
|
44 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a tweet here..."),
|
45 |
+
outputs="text",
|
46 |
+
title="Tweet",
|
47 |
+
description="Enter a tweet and get the prediction (preal disaster or not real disaster)."
|
48 |
+
)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
demo.launch(share=True)
|
disaster_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:334eb2d1c2a38b57d4ef83a2151d3a76bd41bd56d602c2e8c85bfc7b42506a47
|
3 |
+
size 2533612
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
keras
|
3 |
+
gradio
|
4 |
+
scikit-learn
|
5 |
+
joblib
|
6 |
+
nltk
|
tfidf_vectorizer.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ebd1db5d2385e30a898e84996d76e08ded63c2065c361a9db875518b0052fbcb
|
3 |
+
size 2084939
|