├── Get Model.ipynb
├── Model Building.ipynb
├── README.md
├── __init__.py
├── __pycache__
├── __init__.cpython-310.pyc
└── get_tweets.cpython-310.pyc
├── dataset
└── twitter_sentiments.csv
├── get_sentiment.py
├── get_tweets.py
├── templates
└── home.html
└── text_classification.joblib
/Get Model.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import pandas as pd\n",
10 | "from joblib import load"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 5,
16 | "metadata": {},
17 | "outputs": [],
18 | "source": [
19 | "text = [\"Virat Kohli, AB de Villiers set to auction their 'Green Day' kits from 2016 IPL match to raise funds\"]"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 6,
25 | "metadata": {},
26 | "outputs": [],
27 | "source": [
28 | "pipeline = load(\"text_classification.joblib\")"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": 7,
34 | "metadata": {},
35 | "outputs": [
36 | {
37 | "data": {
38 | "text/plain": [
39 | "array([0])"
40 | ]
41 | },
42 | "execution_count": 7,
43 | "metadata": {},
44 | "output_type": "execute_result"
45 | }
46 | ],
47 | "source": [
48 | "pipeline.predict(text)"
49 | ]
50 | },
51 | {
52 | "cell_type": "code",
53 | "execution_count": null,
54 | "metadata": {},
55 | "outputs": [],
56 | "source": []
57 | }
58 | ],
59 | "metadata": {
60 | "kernelspec": {
61 | "display_name": "Python 3",
62 | "language": "python",
63 | "name": "python3"
64 | },
65 | "language_info": {
66 | "codemirror_mode": {
67 | "name": "ipython",
68 | "version": 3
69 | },
70 | "file_extension": ".py",
71 | "mimetype": "text/x-python",
72 | "name": "python",
73 | "nbconvert_exporter": "python",
74 | "pygments_lexer": "ipython3",
75 | "version": "3.7.3"
76 | }
77 | },
78 | "nbformat": 4,
79 | "nbformat_minor": 2
80 | }
81 |
--------------------------------------------------------------------------------
/Model Building.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 35,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "# importing required libraries\n",
10 | "import pandas as pd\n",
11 | "from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS, TfidfVectorizer\n",
12 | "from sklearn.linear_model import LogisticRegression\n",
13 | "from sklearn.pipeline import Pipeline\n",
14 | "from sklearn.metrics import f1_score\n",
15 | "from sklearn.model_selection import train_test_split"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 24,
21 | "metadata": {},
22 | "outputs": [],
23 | "source": [
24 | "data = pd.read_csv('dataset/twitter_sentiments.csv')"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": 95,
30 | "metadata": {},
31 | "outputs": [
32 | {
33 | "data": {
34 | "text/html": [
35 | "
\n",
36 | "\n",
49 | "
\n",
50 | " \n",
51 | " \n",
52 | " | \n",
53 | " id | \n",
54 | " label | \n",
55 | " tweet | \n",
56 | "
\n",
57 | " \n",
58 | " \n",
59 | " \n",
60 | " 0 | \n",
61 | " 1 | \n",
62 | " 0 | \n",
63 | " @user when a father is dysfunctional and is s... | \n",
64 | "
\n",
65 | " \n",
66 | " 1 | \n",
67 | " 2 | \n",
68 | " 0 | \n",
69 | " @user @user thanks for #lyft credit i can't us... | \n",
70 | "
\n",
71 | " \n",
72 | " 2 | \n",
73 | " 3 | \n",
74 | " 0 | \n",
75 | " bihday your majesty | \n",
76 | "
\n",
77 | " \n",
78 | " 3 | \n",
79 | " 4 | \n",
80 | " 0 | \n",
81 | " #model i love u take with u all the time in ... | \n",
82 | "
\n",
83 | " \n",
84 | " 4 | \n",
85 | " 5 | \n",
86 | " 0 | \n",
87 | " factsguide: society now #motivation | \n",
88 | "
\n",
89 | " \n",
90 | "
\n",
91 | "
"
92 | ],
93 | "text/plain": [
94 | " id label tweet\n",
95 | "0 1 0 @user when a father is dysfunctional and is s...\n",
96 | "1 2 0 @user @user thanks for #lyft credit i can't us...\n",
97 | "2 3 0 bihday your majesty\n",
98 | "3 4 0 #model i love u take with u all the time in ...\n",
99 | "4 5 0 factsguide: society now #motivation"
100 | ]
101 | },
102 | "execution_count": 95,
103 | "metadata": {},
104 | "output_type": "execute_result"
105 | }
106 | ],
107 | "source": [
108 | "data.head()"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": 96,
114 | "metadata": {},
115 | "outputs": [
116 | {
117 | "data": {
118 | "text/plain": [
119 | "(31962, 3)"
120 | ]
121 | },
122 | "execution_count": 96,
123 | "metadata": {},
124 | "output_type": "execute_result"
125 | }
126 | ],
127 | "source": [
128 | "data.shape"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": 26,
134 | "metadata": {},
135 | "outputs": [
136 | {
137 | "data": {
138 | "text/plain": [
139 | "0 29720\n",
140 | "1 2242\n",
141 | "Name: label, dtype: int64"
142 | ]
143 | },
144 | "execution_count": 26,
145 | "metadata": {},
146 | "output_type": "execute_result"
147 | }
148 | ],
149 | "source": [
150 | "data.label.value_counts()"
151 | ]
152 | },
153 | {
154 | "cell_type": "code",
155 | "execution_count": 27,
156 | "metadata": {},
157 | "outputs": [],
158 | "source": [
159 | "train, test = train_test_split(data, test_size = 0.2, stratify = data['label'], random_state=21)"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": 28,
165 | "metadata": {
166 | "scrolled": true
167 | },
168 | "outputs": [
169 | {
170 | "data": {
171 | "text/plain": [
172 | "((25569, 3), (6393, 3))"
173 | ]
174 | },
175 | "execution_count": 28,
176 | "metadata": {},
177 | "output_type": "execute_result"
178 | }
179 | ],
180 | "source": [
181 | "train.shape, test.shape"
182 | ]
183 | },
184 | {
185 | "cell_type": "code",
186 | "execution_count": 29,
187 | "metadata": {},
188 | "outputs": [
189 | {
190 | "data": {
191 | "text/plain": [
192 | "0 0.929837\n",
193 | "1 0.070163\n",
194 | "Name: label, dtype: float64"
195 | ]
196 | },
197 | "execution_count": 29,
198 | "metadata": {},
199 | "output_type": "execute_result"
200 | }
201 | ],
202 | "source": [
203 | "train.label.value_counts(normalize=True)"
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": 30,
209 | "metadata": {},
210 | "outputs": [
211 | {
212 | "data": {
213 | "text/plain": [
214 | "0 0.929923\n",
215 | "1 0.070077\n",
216 | "Name: label, dtype: float64"
217 | ]
218 | },
219 | "execution_count": 30,
220 | "metadata": {},
221 | "output_type": "execute_result"
222 | }
223 | ],
224 | "source": [
225 | "test.label.value_counts(normalize=True)"
226 | ]
227 | },
228 | {
229 | "cell_type": "code",
230 | "execution_count": 61,
231 | "metadata": {},
232 | "outputs": [],
233 | "source": [
234 | "tfidf_vectorizer = TfidfVectorizer(lowercase= True, max_features=1000, stop_words=ENGLISH_STOP_WORDS)"
235 | ]
236 | },
237 | {
238 | "cell_type": "code",
239 | "execution_count": 62,
240 | "metadata": {},
241 | "outputs": [
242 | {
243 | "data": {
244 | "text/plain": [
245 | "TfidfVectorizer(analyzer='word', binary=False, decode_error='strict',\n",
246 | " dtype=, encoding='utf-8',\n",
247 | " input='content', lowercase=True, max_df=1.0, max_features=1000,\n",
248 | " min_df=1, ngram_range=(1, 1), norm='l2', preprocessor=None,\n",
249 | " smooth_idf=True,\n",
250 | " stop_words=frozenset({'a', 'about', 'above', 'across', 'after',\n",
251 | " 'afterwards', 'again', 'against', 'all',\n",
252 | " 'almost', 'alone', 'along', 'already',\n",
253 | " 'also', 'although', 'always', 'am',\n",
254 | " 'among', 'amongst', 'amoungst', 'amount',\n",
255 | " 'an', 'and', 'another', 'any', 'anyhow',\n",
256 | " 'anyone', 'anything', 'anyway',\n",
257 | " 'anywhere', ...}),\n",
258 | " strip_accents=None, sublinear_tf=False,\n",
259 | " token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b', tokenizer=None, use_idf=True,\n",
260 | " vocabulary=None)"
261 | ]
262 | },
263 | "execution_count": 62,
264 | "metadata": {},
265 | "output_type": "execute_result"
266 | }
267 | ],
268 | "source": [
269 | "tfidf_vectorizer.fit(train.tweet)"
270 | ]
271 | },
272 | {
273 | "cell_type": "code",
274 | "execution_count": 63,
275 | "metadata": {},
276 | "outputs": [],
277 | "source": [
278 | "train_idf = tfidf_vectorizer.transform(train.tweet)\n",
279 | "test_idf = tfidf_vectorizer.transform(test.tweet)"
280 | ]
281 | },
282 | {
283 | "cell_type": "code",
284 | "execution_count": 64,
285 | "metadata": {},
286 | "outputs": [],
287 | "source": [
288 | "model_LR = LogisticRegression()"
289 | ]
290 | },
291 | {
292 | "cell_type": "code",
293 | "execution_count": 65,
294 | "metadata": {},
295 | "outputs": [
296 | {
297 | "data": {
298 | "text/plain": [
299 | "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
300 | " intercept_scaling=1, l1_ratio=None, max_iter=100,\n",
301 | " multi_class='auto', n_jobs=None, penalty='l2',\n",
302 | " random_state=None, solver='lbfgs', tol=0.0001, verbose=0,\n",
303 | " warm_start=False)"
304 | ]
305 | },
306 | "execution_count": 65,
307 | "metadata": {},
308 | "output_type": "execute_result"
309 | }
310 | ],
311 | "source": [
312 | "model_LR.fit(train_idf, train.label)"
313 | ]
314 | },
315 | {
316 | "cell_type": "code",
317 | "execution_count": 66,
318 | "metadata": {},
319 | "outputs": [],
320 | "source": [
321 | "predict_train = model_LR.predict(train_idf)"
322 | ]
323 | },
324 | {
325 | "cell_type": "code",
326 | "execution_count": 67,
327 | "metadata": {},
328 | "outputs": [],
329 | "source": [
330 | "predict_test = model_LR.predict(test_idf)"
331 | ]
332 | },
333 | {
334 | "cell_type": "code",
335 | "execution_count": 68,
336 | "metadata": {},
337 | "outputs": [
338 | {
339 | "data": {
340 | "text/plain": [
341 | "0.4888178913738019"
342 | ]
343 | },
344 | "execution_count": 68,
345 | "metadata": {},
346 | "output_type": "execute_result"
347 | }
348 | ],
349 | "source": [
350 | "# f1 score on train data\n",
351 | "f1_score(y_true= train.label, y_pred= predict_train)"
352 | ]
353 | },
354 | {
355 | "cell_type": "code",
356 | "execution_count": 69,
357 | "metadata": {},
358 | "outputs": [
359 | {
360 | "data": {
361 | "text/plain": [
362 | "0.45751633986928114"
363 | ]
364 | },
365 | "execution_count": 69,
366 | "metadata": {},
367 | "output_type": "execute_result"
368 | }
369 | ],
370 | "source": [
371 | "f1_score(y_true= test.label, y_pred= predict_test)"
372 | ]
373 | },
374 | {
375 | "cell_type": "code",
376 | "execution_count": 73,
377 | "metadata": {},
378 | "outputs": [],
379 | "source": [
380 | "pipeline = Pipeline(steps= [('tfidf', TfidfVectorizer(lowercase=True,\n",
381 | " max_features=1000,\n",
382 | " stop_words= ENGLISH_STOP_WORDS)),\n",
383 | " ('model', LogisticRegression())])"
384 | ]
385 | },
386 | {
387 | "cell_type": "code",
388 | "execution_count": 75,
389 | "metadata": {},
390 | "outputs": [
391 | {
392 | "data": {
393 | "text/plain": [
394 | "Pipeline(memory=None,\n",
395 | " steps=[('tfidf',\n",
396 | " TfidfVectorizer(analyzer='word', binary=False,\n",
397 | " decode_error='strict',\n",
398 | " dtype=,\n",
399 | " encoding='utf-8', input='content',\n",
400 | " lowercase=True, max_df=1.0, max_features=1000,\n",
401 | " min_df=1, ngram_range=(1, 1), norm='l2',\n",
402 | " preprocessor=None, smooth_idf=True,\n",
403 | " stop_words=frozenset({'a', 'about', 'above',\n",
404 | " 'across', 'after',\n",
405 | " 'afterward...\n",
406 | " strip_accents=None, sublinear_tf=False,\n",
407 | " token_pattern='(?u)\\\\b\\\\w\\\\w+\\\\b',\n",
408 | " tokenizer=None, use_idf=True,\n",
409 | " vocabulary=None)),\n",
410 | " ('model',\n",
411 | " LogisticRegression(C=1.0, class_weight=None, dual=False,\n",
412 | " fit_intercept=True, intercept_scaling=1,\n",
413 | " l1_ratio=None, max_iter=100,\n",
414 | " multi_class='auto', n_jobs=None,\n",
415 | " penalty='l2', random_state=None,\n",
416 | " solver='lbfgs', tol=0.0001, verbose=0,\n",
417 | " warm_start=False))],\n",
418 | " verbose=False)"
419 | ]
420 | },
421 | "execution_count": 75,
422 | "metadata": {},
423 | "output_type": "execute_result"
424 | }
425 | ],
426 | "source": [
427 | "pipeline.fit(train.tweet, train.label)"
428 | ]
429 | },
430 | {
431 | "cell_type": "code",
432 | "execution_count": 77,
433 | "metadata": {},
434 | "outputs": [
435 | {
436 | "data": {
437 | "text/plain": [
438 | "array([0, 0, 0, ..., 0, 0, 0])"
439 | ]
440 | },
441 | "execution_count": 77,
442 | "metadata": {},
443 | "output_type": "execute_result"
444 | }
445 | ],
446 | "source": [
447 | "pipeline.predict(train.tweet)"
448 | ]
449 | },
450 | {
451 | "cell_type": "code",
452 | "execution_count": 93,
453 | "metadata": {},
454 | "outputs": [],
455 | "source": [
456 | "text = [\"Virat Kohli, AB de Villiers set to auction their 'Green Day' kits from 2016 IPL match to raise funds\"]"
457 | ]
458 | },
459 | {
460 | "cell_type": "code",
461 | "execution_count": 94,
462 | "metadata": {},
463 | "outputs": [
464 | {
465 | "data": {
466 | "text/plain": [
467 | "array([0])"
468 | ]
469 | },
470 | "execution_count": 94,
471 | "metadata": {},
472 | "output_type": "execute_result"
473 | }
474 | ],
475 | "source": [
476 | "pipeline.predict(text)"
477 | ]
478 | },
479 | {
480 | "cell_type": "code",
481 | "execution_count": 89,
482 | "metadata": {},
483 | "outputs": [],
484 | "source": [
485 | "from joblib import dump"
486 | ]
487 | },
488 | {
489 | "cell_type": "code",
490 | "execution_count": 90,
491 | "metadata": {},
492 | "outputs": [
493 | {
494 | "data": {
495 | "text/plain": [
496 | "['text_classification.joblib']"
497 | ]
498 | },
499 | "execution_count": 90,
500 | "metadata": {},
501 | "output_type": "execute_result"
502 | }
503 | ],
504 | "source": [
505 | "dump(pipeline, filename=\"text_classification.joblib\")"
506 | ]
507 | },
508 | {
509 | "cell_type": "code",
510 | "execution_count": 92,
511 | "metadata": {},
512 | "outputs": [
513 | {
514 | "data": {
515 | "text/html": [
516 | "\n",
517 | "\n",
530 | "
\n",
531 | " \n",
532 | " \n",
533 | " | \n",
534 | " id | \n",
535 | " label | \n",
536 | " tweet | \n",
537 | "
\n",
538 | " \n",
539 | " \n",
540 | " \n",
541 | " 13 | \n",
542 | " 14 | \n",
543 | " 1 | \n",
544 | " @user #cnn calls #michigan middle school 'buil... | \n",
545 | "
\n",
546 | " \n",
547 | " 14 | \n",
548 | " 15 | \n",
549 | " 1 | \n",
550 | " no comment! in #australia #opkillingbay #se... | \n",
551 | "
\n",
552 | " \n",
553 | " 17 | \n",
554 | " 18 | \n",
555 | " 1 | \n",
556 | " retweet if you agree! | \n",
557 | "
\n",
558 | " \n",
559 | " 23 | \n",
560 | " 24 | \n",
561 | " 1 | \n",
562 | " @user @user lumpy says i am a . prove it lumpy. | \n",
563 | "
\n",
564 | " \n",
565 | " 34 | \n",
566 | " 35 | \n",
567 | " 1 | \n",
568 | " it's unbelievable that in the 21st century we'... | \n",
569 | "
\n",
570 | " \n",
571 | " ... | \n",
572 | " ... | \n",
573 | " ... | \n",
574 | " ... | \n",
575 | "
\n",
576 | " \n",
577 | " 31934 | \n",
578 | " 31935 | \n",
579 | " 1 | \n",
580 | " lady banned from kentucky mall. @user #jcpenn... | \n",
581 | "
\n",
582 | " \n",
583 | " 31946 | \n",
584 | " 31947 | \n",
585 | " 1 | \n",
586 | " @user omfg i'm offended! i'm a mailbox and i'... | \n",
587 | "
\n",
588 | " \n",
589 | " 31947 | \n",
590 | " 31948 | \n",
591 | " 1 | \n",
592 | " @user @user you don't have the balls to hashta... | \n",
593 | "
\n",
594 | " \n",
595 | " 31948 | \n",
596 | " 31949 | \n",
597 | " 1 | \n",
598 | " makes you ask yourself, who am i? then am i a... | \n",
599 | "
\n",
600 | " \n",
601 | " 31960 | \n",
602 | " 31961 | \n",
603 | " 1 | \n",
604 | " @user #sikh #temple vandalised in in #calgary,... | \n",
605 | "
\n",
606 | " \n",
607 | "
\n",
608 | "
2242 rows × 3 columns
\n",
609 | "
"
610 | ],
611 | "text/plain": [
612 | " id label tweet\n",
613 | "13 14 1 @user #cnn calls #michigan middle school 'buil...\n",
614 | "14 15 1 no comment! in #australia #opkillingbay #se...\n",
615 | "17 18 1 retweet if you agree! \n",
616 | "23 24 1 @user @user lumpy says i am a . prove it lumpy.\n",
617 | "34 35 1 it's unbelievable that in the 21st century we'...\n",
618 | "... ... ... ...\n",
619 | "31934 31935 1 lady banned from kentucky mall. @user #jcpenn...\n",
620 | "31946 31947 1 @user omfg i'm offended! i'm a mailbox and i'...\n",
621 | "31947 31948 1 @user @user you don't have the balls to hashta...\n",
622 | "31948 31949 1 makes you ask yourself, who am i? then am i a...\n",
623 | "31960 31961 1 @user #sikh #temple vandalised in in #calgary,...\n",
624 | "\n",
625 | "[2242 rows x 3 columns]"
626 | ]
627 | },
628 | "execution_count": 92,
629 | "metadata": {},
630 | "output_type": "execute_result"
631 | }
632 | ],
633 | "source": [
634 | "data[data.label == 1]"
635 | ]
636 | },
637 | {
638 | "cell_type": "code",
639 | "execution_count": null,
640 | "metadata": {},
641 | "outputs": [],
642 | "source": []
643 | }
644 | ],
645 | "metadata": {
646 | "kernelspec": {
647 | "display_name": "Python 3",
648 | "language": "python",
649 | "name": "python3"
650 | },
651 | "language_info": {
652 | "codemirror_mode": {
653 | "name": "ipython",
654 | "version": 3
655 | },
656 | "file_extension": ".py",
657 | "mimetype": "text/x-python",
658 | "name": "python",
659 | "nbconvert_exporter": "python",
660 | "pygments_lexer": "ipython3",
661 | "version": "3.7.3"
662 | }
663 | },
664 | "nbformat": 4,
665 | "nbformat_minor": 2
666 | }
667 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hate-Speech-Classification-deployed-using-Flask
--------------------------------------------------------------------------------
/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/__pycache__/__init__.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lakshay-arora/Hate-Speech-Classification-deployed-using-Flask/f69c873667f327907d1ab2e34ec119eaf75840f6/__pycache__/__init__.cpython-310.pyc
--------------------------------------------------------------------------------
/__pycache__/get_tweets.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lakshay-arora/Hate-Speech-Classification-deployed-using-Flask/f69c873667f327907d1ab2e34ec119eaf75840f6/__pycache__/get_tweets.cpython-310.pyc
--------------------------------------------------------------------------------
/get_sentiment.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template, request, redirect, url_for
2 | from joblib import load
3 | from get_tweets import get_related_tweets
4 |
5 |
6 | pipeline = load("text_classification.joblib")
7 |
8 |
9 | def requestResults(name):
10 | tweets = get_related_tweets(name)
11 | tweets['prediction'] = pipeline.predict(tweets['tweet_text'])
12 | data = str(tweets.prediction.value_counts()) + '\n\n'
13 | return data + str(tweets)
14 |
15 |
16 | app = Flask(__name__)
17 |
18 |
19 | @app.route('/')
20 | def home():
21 | return render_template('home.html')
22 |
23 |
24 | @app.route('/', methods=['POST', 'GET'])
25 | def get_data():
26 | if request.method == 'POST':
27 | user = request.form['search']
28 | return redirect(url_for('success', name=user))
29 |
30 |
31 | @app.route('/success/')
32 | def success(name):
33 | return "" + str(requestResults(name)) + " "
34 |
35 |
36 | if __name__ == '__main__' :
37 | app.run(debug=True)
--------------------------------------------------------------------------------
/get_tweets.py:
--------------------------------------------------------------------------------
1 | import tweepy
2 | import time
3 | import pandas as pd
4 | pd.set_option('display.max_colwidth', 1000)
5 |
6 | # api key
7 | api_key = "Enter API Key"
8 | # api secret key
9 | api_secret_key = "Enter API Secret Key"
10 | # access token
11 | access_token = "Enter Access Token"
12 | # access token secret
13 | access_token_secret = "Enter Access Token Secret"
14 |
15 | authentication = tweepy.OAuthHandler(api_key, api_secret_key)
16 | authentication.set_access_token(access_token, access_token_secret)
17 | api = tweepy.API(authentication, wait_on_rate_limit=True)
18 |
19 | def get_related_tweets(text_query):
20 | # list to store tweets
21 | tweets_list = []
22 | # no of tweets
23 | count = 50
24 | try:
25 | # Pulling individual tweets from query
26 | for tweet in api.search_tweets(q=text_query, count=count):
27 | print(tweet.text)
28 | # Adding to list that contains all tweets
29 | tweets_list.append({'created_at': tweet.created_at,
30 | 'tweet_id': tweet.id,
31 | 'tweet_text': tweet.text})
32 | return pd.DataFrame.from_dict(tweets_list)
33 |
34 | except BaseException as e:
35 | print('failed on_status,', str(e))
36 | time.sleep(3)
--------------------------------------------------------------------------------
/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
83 |
84 |
85 |
86 |
87 |
Home
88 |
89 |
93 |
94 |
95 |
96 |
97 |
Twitter Sentiment Analysis
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/text_classification.joblib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lakshay-arora/Hate-Speech-Classification-deployed-using-Flask/f69c873667f327907d1ab2e34ec119eaf75840f6/text_classification.joblib
--------------------------------------------------------------------------------