Spaces:
Running
Running
File size: 1,913 Bytes
cb77053 6e9bab7 cb77053 b8c9b58 cb77053 52b0385 cb77053 52b0385 cb77053 52b0385 cb77053 |
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 55 56 57 58 59 60 61 |
import re
from textblob import TextBlob
import nltk
import emopy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import torch
import spacy
from flask import Flask, request, render_template
nltk.download('averaged_perceptron_tagger')
nltk.download('punkt')
nltk.download('maxent_ne_chunker')
nltk.download('words')
nlp = spacy.load("en_core_web_sm")
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
text = request.form['text']
paraphrase_option = request.form['paraphrase_option']
remove_special_chars = request.form.get('remove_special_chars')
summarize = request.form.get('summarize')
correct_grammar = request.form.get('correct_grammar')
if correct_grammar:
text = str(TextBlob(text).correct())
if remove_special_chars:
text = re.sub(r'[^\w\s]', '', text)
if summarize:
doc = nlp(text)
sentences = [sent.text for sent in doc.sents]
text = " ".join(sentences[:3]) + "..."
if paraphrase_option == 'repeat':
text = re.sub(r'\b(\w+)\b', r'\1', text)
elif paraphrase_option == 'emotion_detector':
emotion = emopy.EmotionDetector()
emotions = emotion.detect_emotion(text)
emotion_labels = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral']
index = np.argmax(emotions)
emotion = emotion_labels[index]
if emotion == 'happy':
text = text.upper()
elif emotion == 'sad':
text = text.lower()
else:
text = text.capitalize()
return render_template('index.html', text=text)
return render_template('index.html')
if __name__ == '__main__':
app.run(host="0.0.0.0",port=7860,debug=True) |