Spaces:
Running
Running
Commit
·
bd1767a
1
Parent(s):
44fa79c
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,23 @@
|
|
1 |
-
import
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|