-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python-textblob: Add Flask app with sentiment analysis and form handling
- Loading branch information
1 parent
66621a5
commit 8d97975
Showing
13 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
Python-TextBlob with Flask/.idea/Python-TextBlob with Flask.iml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
Python-TextBlob/.idea/misc.xml → Python-TextBlob with Flask/.idea/misc.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
Python-TextBlob/.idea/modules.xml → Python-TextBlob with Flask/.idea/modules.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Review Sentiment Analysis</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
} | ||
|
||
.review-form { | ||
background-color: white; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); | ||
width: 400px; | ||
} | ||
|
||
.review-form h2 { | ||
text-align: center; | ||
} | ||
|
||
.review-form textarea { | ||
width: 100%; | ||
padding: 10px; | ||
border: 1px solid #ddd; | ||
border-radius: 5px; | ||
resize: vertical; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.review-form button { | ||
width: 100%; | ||
padding: 10px; | ||
background-color: #28a745; | ||
color: white; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
} | ||
|
||
.review-form button:hover { | ||
background-color: #218838; | ||
} | ||
|
||
.result { | ||
text-align: center; | ||
font-size: 18px; | ||
margin-top: 15px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="review-form"> | ||
<h2>Review Sentiment Analysis</h2> | ||
<form id="review-form"> | ||
<textarea name="review" id="review" rows="5" placeholder="" required></textarea><br> | ||
<button type="submit">Submit Review</button> | ||
</form> | ||
<div class="result" id="result"> | ||
</div> | ||
</div> | ||
|
||
<script src="/static/js/script.js"></script> | ||
|
||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.