File size: 1,777 Bytes
6e9bab7
 
 
 
 
49be6a8
b8c9b58
6e9bab7
a233401
d4399fb
6e9bab7
 
7609276
6e9bab7
d4399fb
6e9bab7
 
b8c9b58
6e9bab7
 
49be6a8
6e9bab7
 
49be6a8
6e9bab7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Import required libraries
import nltk
import re
import numpy as np
from flask import Flask, request, render_template
from textblob import TextBlob

# Initialize the Flask application
app = Flask(__name__)

# Define the root route
@app.route('/')
def index():
    return render_template('index.html')

# Define the route for paraphrasing text
@app.route('/paraphrase', methods=['POST'])
def paraphrase():
    # Get the input text from the form
    input_text = request.form['input_text']

    # Correct grammar using TextBlob
    corrected_text = TextBlob(input_text).correct()

    # Remove special characters using regular expressions
    cleaned_text = re.sub('[^A-Za-z0-9]+', ' ', corrected_text)

    # Summarize the text using TextBlob
    summarized_text = TextBlob(cleaned_text).summarize()

    # Perform Part-of-Speech (POS) tagging using NLTK
    pos_tagged_text = nltk.pos_tag(summarized_text.words)

    # Perform Named Entity Recognition (NER) using NLTK
    ner_tagged_text = nltk.ne_chunk(pos_tagged_text)

    # Perform sentiment analysis using TextBlob
    sentiment = TextBlob(summarized_text).sentiment

    # Perform emotion detection and adjust the tone of the paraphrased text
    emotion = ""
    if sentiment.polarity >= 0.5:
        emotion = "Positive"
    elif sentiment.polarity > 0 and sentiment.polarity < 0.5:
        emotion = "Neutral"
    else:
        emotion = "Negative"

    # Render the results template with the paraphrased text and analysis results
    return render_template('results.html', paraphrased_text=summarized_text, pos_tagged_text=pos_tagged_text, ner_tagged_text=ner_tagged_text, sentiment=sentiment, emotion=emotion)

# Run the Flask application
if __name__ == '__main__':
    app.run(debug=True,host="0.0.0.0",port=7860)