Spaces:
Running
Running
imseldrith
commited on
Commit
·
e5b3d83
1
Parent(s):
0eed616
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,47 @@
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
outputs=gr.outputs.Textbox(label="Paraphrased text:"),
|
17 |
title="Parrot - Text Paraphrasing",
|
18 |
description="Enter a text to paraphrase using Parrot.",
|
@@ -21,3 +50,10 @@ interface = gr.Interface(
|
|
21 |
|
22 |
# Launch the interface
|
23 |
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from parrot import Parrot
|
3 |
+
from gtts import gTTS
|
4 |
+
from IPython.display import Audio
|
5 |
+
import os
|
6 |
|
7 |
# Create a Parrot instance
|
8 |
parrot = Parrot(model_tag="turing", use_gpu=False)
|
9 |
|
10 |
+
# Supported languages for paraphrasing
|
11 |
+
languages = {
|
12 |
+
"English": "en",
|
13 |
+
"French": "fr",
|
14 |
+
"Spanish": "es",
|
15 |
+
"German": "de"
|
16 |
+
}
|
17 |
+
|
18 |
+
# Supported models for paraphrasing
|
19 |
+
models = {
|
20 |
+
"Turing": "turing",
|
21 |
+
"Pegasus": "pegasus"
|
22 |
+
}
|
23 |
+
|
24 |
+
def paraphrase_text(text, language, model, level):
|
25 |
# Call the Parrot instance to paraphrase the input text
|
26 |
+
result = parrot.predict([text], model_tag=model, context_length=level, src_lang=language, dest_lang=language)
|
27 |
return result[0]['translation_text']
|
28 |
|
29 |
+
def speak_paraphrased_text(text, language):
|
30 |
+
# Use gTTS to generate an audio file of the paraphrased text and play it
|
31 |
+
tts = gTTS(text=text, lang=language)
|
32 |
+
tts.save("paraphrased_text.mp3")
|
33 |
+
return Audio("paraphrased_text.mp3", autoplay=True)
|
34 |
+
|
35 |
# Create a Gradio interface
|
36 |
interface = gr.Interface(
|
37 |
fn=paraphrase_text,
|
38 |
+
inputs=[
|
39 |
+
gr.inputs.Textbox(label="Enter text to paraphrase:"),
|
40 |
+
gr.inputs.Dropdown(list(languages.keys()), label="Select language for paraphrasing:"),
|
41 |
+
gr.inputs.Dropdown(list(models.keys()), label="Select model for paraphrasing:"),
|
42 |
+
gr.inputs.Slider(minimum=1, maximum=10, default=5, label="Level of paraphrasing:"),
|
43 |
+
gr.inputs.Checkbox(label="Generate audio output?")
|
44 |
+
],
|
45 |
outputs=gr.outputs.Textbox(label="Paraphrased text:"),
|
46 |
title="Parrot - Text Paraphrasing",
|
47 |
description="Enter a text to paraphrase using Parrot.",
|
|
|
50 |
|
51 |
# Launch the interface
|
52 |
interface.launch()
|
53 |
+
|
54 |
+
# If the user has selected the "Generate audio output?" checkbox, call the speak_paraphrased_text function to generate and play the audio
|
55 |
+
if interface.inputs[4].value:
|
56 |
+
speak_paraphrased_text(interface.outputs.value, languages[interface.inputs[1].value])
|
57 |
+
|
58 |
+
# Delete the generated audio file
|
59 |
+
os.remove("paraphrased_text.mp3")
|