Spaces:
Runtime error
Runtime error
Commit
·
04f5cbf
1
Parent(s):
e9f7f55
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,12 @@ import pandas as pd
|
|
| 2 |
import numpy as np
|
| 3 |
import nltk
|
| 4 |
import re
|
| 5 |
-
import string
|
| 6 |
from nltk.corpus import stopwords
|
| 7 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 8 |
from sklearn.model_selection import train_test_split
|
| 9 |
from sklearn.linear_model import PassiveAggressiveClassifier
|
| 10 |
import gradio as gr
|
|
|
|
| 11 |
|
| 12 |
# Download NLTK resources if not already downloaded
|
| 13 |
nltk.download('stopwords')
|
|
@@ -46,12 +46,16 @@ tfidf_test = tfidf_vectorizer.transform(X_test)
|
|
| 46 |
passive_aggressive = PassiveAggressiveClassifier()
|
| 47 |
passive_aggressive.fit(tfidf_train, y_train)
|
| 48 |
|
| 49 |
-
#
|
|
|
|
|
|
|
|
|
|
| 50 |
def predict_disaster_tweets(text):
|
| 51 |
cleaned_text = clean_tweet(text)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
# Gradio Interface setup
|
| 57 |
iface = gr.Interface(
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import nltk
|
| 4 |
import re
|
|
|
|
| 5 |
from nltk.corpus import stopwords
|
| 6 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 7 |
from sklearn.model_selection import train_test_split
|
| 8 |
from sklearn.linear_model import PassiveAggressiveClassifier
|
| 9 |
import gradio as gr
|
| 10 |
+
from transformers import pipeline
|
| 11 |
|
| 12 |
# Download NLTK resources if not already downloaded
|
| 13 |
nltk.download('stopwords')
|
|
|
|
| 46 |
passive_aggressive = PassiveAggressiveClassifier()
|
| 47 |
passive_aggressive.fit(tfidf_train, y_train)
|
| 48 |
|
| 49 |
+
# Load the Hugging Face model
|
| 50 |
+
classifier = pipeline("text-classification", model="distilbert-base-uncased")
|
| 51 |
+
|
| 52 |
+
# Function for making predictions using the Hugging Face model
|
| 53 |
def predict_disaster_tweets(text):
|
| 54 |
cleaned_text = clean_tweet(text)
|
| 55 |
+
prediction = classifier(cleaned_text)[0]
|
| 56 |
+
label = prediction['label']
|
| 57 |
+
score = prediction['score']
|
| 58 |
+
return f"Label: {label}, Score: {score}"
|
| 59 |
|
| 60 |
# Gradio Interface setup
|
| 61 |
iface = gr.Interface(
|