Commit
Β·
8a86164
1
Parent(s):
557587b
Added app.py
Browse files- .gitignore +1 -0
- README.md +5 -4
- app.py +38 -0
- assets/negative.jpeg +0 -0
- assets/neutral.jpeg +0 -0
- assets/positive.jpeg +0 -0
- models/dt_twitter.pkl +3 -0
- models/knn_twitter.pkl +3 -0
- models/lg_twitter.pkl +3 -0
- models/nb_twitter.pkl +3 -0
- models/rf_twitter.pkl +3 -0
- requirements.txt +76 -0
- vectorizer.pkl +3 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__/
|
README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
---
|
2 |
title: Twitter Sentiment Analysis
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.31.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Twitter Sentiment Analysis
|
3 |
+
emoji: π
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.31.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: mit
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
|
4 |
+
def load_model(selected_model):
|
5 |
+
with open(selected_model, 'rb') as file:
|
6 |
+
loaded_model = pickle.load(file)
|
7 |
+
return loaded_model
|
8 |
+
|
9 |
+
def predict(model, text):
|
10 |
+
encoder = {
|
11 |
+
0:'assets/negative.jpeg',
|
12 |
+
1:'assets/neutral.jpeg',
|
13 |
+
2:'assets/positive.jpeg'
|
14 |
+
}
|
15 |
+
selected_model = None
|
16 |
+
with open('vectorizer.pkl', 'rb') as file:
|
17 |
+
vectorizer = pickle.load(file)
|
18 |
+
|
19 |
+
if 'Random Forest' == model:
|
20 |
+
selected_model = "models/rf_twitter.pkl"
|
21 |
+
elif 'Logistic Regression' == model:
|
22 |
+
selected_model = "models/lg_twitter.pkl"
|
23 |
+
elif 'Naive Bayes' == model:
|
24 |
+
selected_model = "models/nb_twitter.pkl"
|
25 |
+
elif 'Decision Tree' == model:
|
26 |
+
selected_model = "models/dt_twitter.pkl"
|
27 |
+
elif 'KNN' == model:
|
28 |
+
selected_model = "models/knn_twitter.pkl"
|
29 |
+
else:
|
30 |
+
selected_model = "models/lg_twitter.pkl"
|
31 |
+
loaded_model = load_model(selected_model)
|
32 |
+
text_vector = vectorizer.transform([text])
|
33 |
+
prediction = loaded_model.predict(text_vector)
|
34 |
+
return encoder[prediction[0]]
|
35 |
+
|
36 |
+
models = gr.Radio(['Random Forest', 'Logistic Regression','Naive Bayes','Decision Tree','KNN'], label="Choose model")
|
37 |
+
demo = gr.Interface(fn=predict, inputs=[models,"text"], outputs="image", title="Sentiment Analysis")
|
38 |
+
demo.launch(share=True)
|
assets/negative.jpeg
ADDED
![]() |
assets/neutral.jpeg
ADDED
![]() |
assets/positive.jpeg
ADDED
![]() |
models/dt_twitter.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f7427c1f226174c0b192cc64386b230782ed9a346a2fbb964f1e4a7d56c90f7a
|
3 |
+
size 173206
|
models/knn_twitter.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:10fe0593d64f1fb9bc266a4d79e85e05c147a3edac6d12a89c4eac68d4620751
|
3 |
+
size 1706336
|
models/lg_twitter.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0a501ffd33adfebee1a00270455b491a8a2c0761c6953b1c4571fc6e2f5e93ad
|
3 |
+
size 409544
|
models/nb_twitter.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c781a929e0ea8829f5ad1d370628194b90f665cfbf2ef19434f776832d58fe31
|
3 |
+
size 818217
|
models/rf_twitter.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e39b4494902459acbf2a03a05f09a0284d5cf7ea09ef45263539365862f9a295
|
3 |
+
size 22849926
|
requirements.txt
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
altair==5.3.0
|
3 |
+
annotated-types==0.6.0
|
4 |
+
anyio==4.3.0
|
5 |
+
attrs==23.2.0
|
6 |
+
certifi==2024.2.2
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
colorama==0.4.6
|
10 |
+
contourpy==1.2.1
|
11 |
+
cycler==0.12.1
|
12 |
+
dnspython==2.6.1
|
13 |
+
email_validator==2.1.1
|
14 |
+
fastapi==0.111.0
|
15 |
+
fastapi-cli==0.0.3
|
16 |
+
ffmpy==0.3.2
|
17 |
+
filelock==3.14.0
|
18 |
+
fonttools==4.51.0
|
19 |
+
fsspec==2024.5.0
|
20 |
+
gradio==4.31.3
|
21 |
+
gradio_client==0.16.3
|
22 |
+
h11==0.14.0
|
23 |
+
httpcore==1.0.5
|
24 |
+
httptools==0.6.1
|
25 |
+
httpx==0.27.0
|
26 |
+
huggingface-hub==0.23.0
|
27 |
+
idna==3.7
|
28 |
+
importlib_resources==6.4.0
|
29 |
+
Jinja2==3.1.4
|
30 |
+
joblib==1.4.2
|
31 |
+
jsonschema==4.22.0
|
32 |
+
jsonschema-specifications==2023.12.1
|
33 |
+
kiwisolver==1.4.5
|
34 |
+
markdown-it-py==3.0.0
|
35 |
+
MarkupSafe==2.1.5
|
36 |
+
matplotlib==3.9.0
|
37 |
+
mdurl==0.1.2
|
38 |
+
numpy==1.26.4
|
39 |
+
orjson==3.10.3
|
40 |
+
packaging==24.0
|
41 |
+
pandas==2.2.2
|
42 |
+
pillow==10.3.0
|
43 |
+
pydantic==2.7.1
|
44 |
+
pydantic_core==2.18.2
|
45 |
+
pydub==0.25.1
|
46 |
+
Pygments==2.18.0
|
47 |
+
pyparsing==3.1.2
|
48 |
+
python-dateutil==2.9.0.post0
|
49 |
+
python-dotenv==1.0.1
|
50 |
+
python-multipart==0.0.9
|
51 |
+
pytz==2024.1
|
52 |
+
PyYAML==6.0.1
|
53 |
+
referencing==0.35.1
|
54 |
+
requests==2.31.0
|
55 |
+
rich==13.7.1
|
56 |
+
rpds-py==0.18.1
|
57 |
+
ruff==0.4.4
|
58 |
+
scikit-learn==1.4.2
|
59 |
+
scipy==1.13.0
|
60 |
+
semantic-version==2.10.0
|
61 |
+
shellingham==1.5.4
|
62 |
+
six==1.16.0
|
63 |
+
sniffio==1.3.1
|
64 |
+
starlette==0.37.2
|
65 |
+
threadpoolctl==3.5.0
|
66 |
+
tomlkit==0.12.0
|
67 |
+
toolz==0.12.1
|
68 |
+
tqdm==4.66.4
|
69 |
+
typer==0.12.3
|
70 |
+
typing_extensions==4.11.0
|
71 |
+
tzdata==2024.1
|
72 |
+
ujson==5.10.0
|
73 |
+
urllib3==2.2.1
|
74 |
+
uvicorn==0.29.0
|
75 |
+
watchfiles==0.21.0
|
76 |
+
websockets==11.0.3
|
vectorizer.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cff2d31eea3389535165621b202e2b043185a19e56492bb9da8fa32a1bf1dce1
|
3 |
+
size 484905
|