From 8d979754a20cd534a032d5b9ab44a0b830b37574 Mon Sep 17 00:00:00 2001
From: Charaka V Mihiranga
<143955766+CharakaMihiranga@users.noreply.github.com>
Date: Wed, 18 Sep 2024 11:07:48 +0530
Subject: [PATCH] Python-textblob: Add Flask app with sentiment analysis and
form handling
---
.../.idea/.gitignore | 0
.../.idea/Python-TextBlob with Flask.iml | 21 +++++
.../inspectionProfiles/Project_Default.xml | 0
.../inspectionProfiles/profiles_settings.xml | 0
.../.idea/misc.xml | 4 +-
.../.idea/modules.xml | 2 +-
.../.idea/vcs.xml | 0
.../__pycache__/app.cpython-312.pyc | Bin 0 -> 1345 bytes
Python-TextBlob with Flask/app.py | 30 +++++++
.../static/js/script.js | 16 ++++
.../templates/index.html | 75 ++++++++++++++++++
Python-TextBlob/.idea/Python-TextBlob.iml | 10 ---
Python-TextBlob/main.py | 12 ---
13 files changed, 145 insertions(+), 25 deletions(-)
rename {Python-TextBlob => Python-TextBlob with Flask}/.idea/.gitignore (100%)
create mode 100644 Python-TextBlob with Flask/.idea/Python-TextBlob with Flask.iml
rename {Python-TextBlob => Python-TextBlob with Flask}/.idea/inspectionProfiles/Project_Default.xml (100%)
rename {Python-TextBlob => Python-TextBlob with Flask}/.idea/inspectionProfiles/profiles_settings.xml (100%)
rename {Python-TextBlob => Python-TextBlob with Flask}/.idea/misc.xml (52%)
rename {Python-TextBlob => Python-TextBlob with Flask}/.idea/modules.xml (72%)
rename {Python-TextBlob => Python-TextBlob with Flask}/.idea/vcs.xml (100%)
create mode 100644 Python-TextBlob with Flask/__pycache__/app.cpython-312.pyc
create mode 100644 Python-TextBlob with Flask/app.py
create mode 100644 Python-TextBlob with Flask/static/js/script.js
create mode 100644 Python-TextBlob with Flask/templates/index.html
delete mode 100644 Python-TextBlob/.idea/Python-TextBlob.iml
delete mode 100644 Python-TextBlob/main.py
diff --git a/Python-TextBlob/.idea/.gitignore b/Python-TextBlob with Flask/.idea/.gitignore
similarity index 100%
rename from Python-TextBlob/.idea/.gitignore
rename to Python-TextBlob with Flask/.idea/.gitignore
diff --git a/Python-TextBlob with Flask/.idea/Python-TextBlob with Flask.iml b/Python-TextBlob with Flask/.idea/Python-TextBlob with Flask.iml
new file mode 100644
index 0000000..2533b8d
--- /dev/null
+++ b/Python-TextBlob with Flask/.idea/Python-TextBlob with Flask.iml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Python-TextBlob/.idea/inspectionProfiles/Project_Default.xml b/Python-TextBlob with Flask/.idea/inspectionProfiles/Project_Default.xml
similarity index 100%
rename from Python-TextBlob/.idea/inspectionProfiles/Project_Default.xml
rename to Python-TextBlob with Flask/.idea/inspectionProfiles/Project_Default.xml
diff --git a/Python-TextBlob/.idea/inspectionProfiles/profiles_settings.xml b/Python-TextBlob with Flask/.idea/inspectionProfiles/profiles_settings.xml
similarity index 100%
rename from Python-TextBlob/.idea/inspectionProfiles/profiles_settings.xml
rename to Python-TextBlob with Flask/.idea/inspectionProfiles/profiles_settings.xml
diff --git a/Python-TextBlob/.idea/misc.xml b/Python-TextBlob with Flask/.idea/misc.xml
similarity index 52%
rename from Python-TextBlob/.idea/misc.xml
rename to Python-TextBlob with Flask/.idea/misc.xml
index 0a67c5e..2f252d2 100644
--- a/Python-TextBlob/.idea/misc.xml
+++ b/Python-TextBlob with Flask/.idea/misc.xml
@@ -1,7 +1,7 @@
-
+
-
+
\ No newline at end of file
diff --git a/Python-TextBlob/.idea/modules.xml b/Python-TextBlob with Flask/.idea/modules.xml
similarity index 72%
rename from Python-TextBlob/.idea/modules.xml
rename to Python-TextBlob with Flask/.idea/modules.xml
index e48df9a..a5e3e48 100644
--- a/Python-TextBlob/.idea/modules.xml
+++ b/Python-TextBlob with Flask/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/Python-TextBlob/.idea/vcs.xml b/Python-TextBlob with Flask/.idea/vcs.xml
similarity index 100%
rename from Python-TextBlob/.idea/vcs.xml
rename to Python-TextBlob with Flask/.idea/vcs.xml
diff --git a/Python-TextBlob with Flask/__pycache__/app.cpython-312.pyc b/Python-TextBlob with Flask/__pycache__/app.cpython-312.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..dbf6ccfc91a5bf2142b846f4db3298910d1fe739
GIT binary patch
literal 1345
zcmZ`&&2Jk;6rb50?{2(tYA2}RMk(e1%~m3zLP992dO&GHg%kqrA+jP_TXr0;vmfs4
zY+FaMa4A)jN`QL`2c+b{1%(rT1Q#wTmRf5B0s)uyv{7z3F*CMPr&6D^Z{PR4_vSah
zWin~N>GjI<$}b84{|aS5s4pD-%7q=^00(-&hb8DMCB;`us*g$t3cKQ^e66HGpa2Z9
zz7KnuB?B9^i9xv+e@7ieIOuDz-*=SKuZT`L+8X>>-{<`aa*UxI6YI{%`ZNF}$FuXj
zh+#gc4nZT`NL%JJ;j|D-EqHdc&UAur#yFzv48eheNtt55?%5PGy%vRmTWMI38Q1Y0
z`jHpjIEJ%d3>R0qBEF+HINJfVKR53Y4kj!DOIg}TyS(_FnJV=?3z8I%{s|m$4vw$P
zf-b7q5Qs;cD^frS~K&6mb-}VGyk@H)u5s-W{A@xb4zvL3X}s*XuL&21C`*$0Wl`
z8T^Zc&;tLN=f1z(F{cmEG%>klV{FzAY_G9_3BKjx+YBv#TD;CD(|ybjaH3OFiF=n*
zJ>kOeRJHyMaPtWb_S*!Tpe6=;iC%1?38_ACZl3I?scb4W(fUhNlej!>Y^s~8qpZ*K
z+g2U5iGnjy=Us6fab1_XK!f6>nuv;RNOH6yse20-
zK9@`S=ZE{r?zh{q0PqrCvxi*C?*5PQxU|QV*j_&)*?sg48;Nj0U7s^cCt{V%Si`g|
z(8N?O5wQd!l9^EtJ)5|+K{T#fDTW-I+9W4@=my7IFN`-D#U72sb_;^YsEEj%x>6#r
zFYM7eX95D_PtD24=48j5YRz{ux$joCSK8H1=FQf^ALc}Rp<_;Rd-k=Ru}5Q1vlkv`
zFSM@xt!LYpzG`-J*0$Ci8E=2~aH^YorzhJF&v$cgZ)v=6`;)!12NTmB(>g$w1Q;{Q
zW#4v#a(T(huvA67Eg~=^Hy{BoXJiKDPf3m@)*#XX+sEZHQ#qblii9!kp;^wuR1yb7
zAVHoY=RP(r`=Jwi_zHQ8JH(TVZgQ5W5W>H}TnEhk38oG;ppR~Sd@pRNi3XI^gZ$n6
z*8BI)A1V-9M=DUViI7fw2j=8nWpAaG@4%TuB?B*tnAt=~NdchIt&QK+d>82t7Vj?J
Mzm})~os%v74_sz3RR910
literal 0
HcmV?d00001
diff --git a/Python-TextBlob with Flask/app.py b/Python-TextBlob with Flask/app.py
new file mode 100644
index 0000000..3942b89
--- /dev/null
+++ b/Python-TextBlob with Flask/app.py
@@ -0,0 +1,30 @@
+from flask import Flask, request, render_template, jsonify
+from textblob import TextBlob
+
+
+app = Flask(__name__)
+
+
+@app.route('/')
+def home():
+ return render_template('index.html')
+
+@app.route('/analyzereview', methods=['POST'])
+def analyzereview():
+ data = request.get_json()
+ review = data.get('review')
+ blob = TextBlob(review)
+ sentiment = blob.sentiment.polarity
+
+ if sentiment > 0:
+ result = "Positive Review✅🎉"
+ elif sentiment < 0:
+ result = "Negative Review🫤"
+ elif sentiment == 0:
+ result = "Neutral Review👍"
+
+ return jsonify({'sentiment': result})
+
+
+if __name__ == '__main__':
+ app.run()
diff --git a/Python-TextBlob with Flask/static/js/script.js b/Python-TextBlob with Flask/static/js/script.js
new file mode 100644
index 0000000..1b22ff4
--- /dev/null
+++ b/Python-TextBlob with Flask/static/js/script.js
@@ -0,0 +1,16 @@
+ document.getElementById('review-form').addEventListener('submit', async function(event) {
+ event.preventDefault();
+
+ const reviewText = document.getElementById('review').value;
+
+ const response = await fetch('/analyzereview', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({ review: reviewText })
+ });
+
+ const data = await response.json();
+ document.getElementById('result').textContent = 'Sentiment: ' + data.sentiment;
+ });
\ No newline at end of file
diff --git a/Python-TextBlob with Flask/templates/index.html b/Python-TextBlob with Flask/templates/index.html
new file mode 100644
index 0000000..2f48b5e
--- /dev/null
+++ b/Python-TextBlob with Flask/templates/index.html
@@ -0,0 +1,75 @@
+
+
+
+
+
+ Review Sentiment Analysis
+
+
+
+
+
+
+
+
+
+
diff --git a/Python-TextBlob/.idea/Python-TextBlob.iml b/Python-TextBlob/.idea/Python-TextBlob.iml
deleted file mode 100644
index 2c80e12..0000000
--- a/Python-TextBlob/.idea/Python-TextBlob.iml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Python-TextBlob/main.py b/Python-TextBlob/main.py
deleted file mode 100644
index a8e0342..0000000
--- a/Python-TextBlob/main.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from textblob import TextBlob
-# import nltk
-# nltk.download('all') // to download natural language toolkit
-
-testimonial = TextBlob("Textblob is amazingly simple to use. What great fun!")
-
-
-if __name__ == '__main__':
- print(testimonial.sentiment)
- print(testimonial.sentiment.polarity)
-
-