Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- app.py +26 -0
- logistic_model.pkl +3 -0
- requirements.txt +4 -0
- tfidf_vectorizer.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Load model and vectorizer
|
| 6 |
+
model = joblib.load("logistic_model.pkl")
|
| 7 |
+
vectorizer = joblib.load("tfidf_vectorizer.pkl")
|
| 8 |
+
|
| 9 |
+
# Prediction function
|
| 10 |
+
def predict_disaster(text):
|
| 11 |
+
text_df = pd.DataFrame([text], columns=["text"])
|
| 12 |
+
text_transformed = vectorizer.transform(text_df["text"])
|
| 13 |
+
prediction = model.predict(text_transformed)
|
| 14 |
+
label = "Disaster Tweet" if prediction[0] == 1 else "Not a Disaster Tweet"
|
| 15 |
+
return label
|
| 16 |
+
|
| 17 |
+
# Gradio Interface
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=predict_disaster,
|
| 20 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter the tweet here..."),
|
| 21 |
+
outputs="text",
|
| 22 |
+
title="Disaster Tweet Classifier",
|
| 23 |
+
description="Classifies whether a tweet is about a real disaster or not.",
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
iface.launch()
|
logistic_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ff47ef384e6c40e56a53056ecb03993ba5970b9df7e4a7a2016904950ff9462a
|
| 3 |
+
size 4778322
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
scikit-learn
|
| 3 |
+
joblib
|
| 4 |
+
pandas
|
tfidf_vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eaf14e82d92a2b2aae5f6f2be9bb8cff2fc0f37ab3d511014bfa9db2c2539171
|
| 3 |
+
size 178757
|