# 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)