imseldrith commited on
Commit
bd1767a
·
1 Parent(s): 44fa79c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -61
app.py CHANGED
@@ -1,61 +1,23 @@
1
- import re
2
- from textblob import TextBlob
3
- import nltk
4
- import emopy
5
- import numpy as np
6
- import pandas as pd
7
- import matplotlib.pyplot as plt
8
- import seaborn as sns
9
- import torch
10
- import spacy
11
- from flask import Flask, request, render_template
12
-
13
- nltk.download('averaged_perceptron_tagger')
14
- nltk.download('punkt')
15
- nltk.download('maxent_ne_chunker')
16
- nltk.download('words')
17
-
18
- nlp = spacy.load("en_core_web_sm")
19
-
20
- app = Flask(__name__)
21
-
22
- @app.route('/', methods=['GET', 'POST'])
23
- def index():
24
- if request.method == 'POST':
25
- text = request.form['text']
26
- paraphrase_option = request.form['paraphrase_option']
27
- remove_special_chars = request.form.get('remove_special_chars')
28
- summarize = request.form.get('summarize')
29
- correct_grammar = request.form.get('correct_grammar')
30
-
31
- if correct_grammar:
32
- text = str(TextBlob(text).correct())
33
-
34
- if remove_special_chars:
35
- text = re.sub(r'[^\w\s]', '', text)
36
-
37
- if summarize:
38
- doc = nlp(text)
39
- sentences = [sent.text for sent in doc.sents]
40
- text = " ".join(sentences[:3]) + "..."
41
-
42
- if paraphrase_option == 'repeat':
43
- text = re.sub(r'\b(\w+)\b', r'\1', text)
44
- elif paraphrase_option == 'emotion_detector':
45
- emotion = emopy.EmotionDetector()
46
- emotions = emotion.detect_emotion(text)
47
- emotion_labels = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral']
48
- index = np.argmax(emotions)
49
- emotion = emotion_labels[index]
50
- if emotion == 'happy':
51
- text = text.upper()
52
- elif emotion == 'sad':
53
- text = text.lower()
54
- else:
55
- text = text.capitalize()
56
-
57
- return render_template('index.html', text=text)
58
- return render_template('index.html')
59
-
60
- if __name__ == '__main__':
61
- app.run(host="0.0.0.0",port=7860,debug=True)
 
1
+ import gradio as gr
2
+ from parrot import Parrot
3
+
4
+ # Create a Parrot instance
5
+ parrot = Parrot(model_tag="turing", use_gpu=False)
6
+
7
+ def paraphrase_text(text):
8
+ # Call the Parrot instance to paraphrase the input text
9
+ result = parrot.predict([text])
10
+ return result[0]['translation_text']
11
+
12
+ # Create a Gradio interface
13
+ interface = gr.Interface(
14
+ fn=paraphrase_text,
15
+ inputs=gr.inputs.Textbox(label="Enter text to paraphrase:"),
16
+ outputs=gr.outputs.Textbox(label="Paraphrased text:"),
17
+ title="Parrot - Text Paraphrasing",
18
+ description="Enter a text to paraphrase using Parrot.",
19
+ theme="default"
20
+ )
21
+
22
+ # Launch the interface
23
+ interface.launch()