feat: add slider for adequacy and fluency
Browse files- app.py +9 -3
- frasaria/frasaria.py +7 -14
app.py
CHANGED
@@ -2,9 +2,15 @@ import gradio as gr
|
|
2 |
from frasaria.frasaria import paraphrase_text
|
3 |
|
4 |
demo = gr.Interface(
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
)
|
9 |
|
10 |
if __name__ == '__main__':
|
|
|
2 |
from frasaria.frasaria import paraphrase_text
|
3 |
|
4 |
demo = gr.Interface(
|
5 |
+
paraphrase_text,
|
6 |
+
[
|
7 |
+
gr.Slider(0.1, 0.99, value=0.90, label="Adequacy",
|
8 |
+
info='Adequacy menunjukkan sejauh mana kalimat yang dihasilkan memiliki makna yang sama dengan kalimat asli. Kurangi nilai ini untuk mendapatkan kalimat yang lebih berbeda.'),
|
9 |
+
gr.Slider(0.1, 0.99, value=0.90, label="Fluency",
|
10 |
+
info='Fluency menunjukkan sejauh mana kalimat yang dihasilkan terdengar alami.'),
|
11 |
+
gr.Textbox(lines=5, label="Text Input")
|
12 |
+
],
|
13 |
+
'textbox'
|
14 |
)
|
15 |
|
16 |
if __name__ == '__main__':
|
frasaria/frasaria.py
CHANGED
@@ -8,26 +8,19 @@ def split_sentences(text: str):
|
|
8 |
return [sentence.strip() for sentence in text.split(".")]
|
9 |
|
10 |
|
11 |
-
def paraphrase(phrases):
|
12 |
-
para_phrases = parrot.augment(phrases, max_return_phrases=
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
if score > max_score:
|
18 |
-
max_score = score
|
19 |
-
paraphrased = para_phrase[0]
|
20 |
-
return paraphrased
|
21 |
-
|
22 |
-
|
23 |
-
def paraphrase_text(phrase):
|
24 |
phrase = phrase.replace('"', "'")
|
25 |
result = translator.translate_text(phrase, target_lang="EN-US")
|
26 |
|
27 |
# paraphrase
|
28 |
sentences = []
|
29 |
for translated in split_sentences(result.text)[:-1]:
|
30 |
-
sentences.append(paraphrase(translated))
|
31 |
|
32 |
text = '. '.join(list(map(lambda x: x.capitalize(), sentences))) + '.'
|
33 |
if result.detected_source_lang == 'EN':
|
|
|
8 |
return [sentence.strip() for sentence in text.split(".")]
|
9 |
|
10 |
|
11 |
+
def paraphrase(adequacy, fluency, phrases):
|
12 |
+
para_phrases = parrot.augment(phrases, max_return_phrases=1, adequacy_threshold=adequacy, fluency_threshold=fluency)
|
13 |
+
return para_phrases[0][0] if para_phrases else phrases
|
14 |
+
|
15 |
+
|
16 |
+
def paraphrase_text(adequacy, fluency, phrase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
phrase = phrase.replace('"', "'")
|
18 |
result = translator.translate_text(phrase, target_lang="EN-US")
|
19 |
|
20 |
# paraphrase
|
21 |
sentences = []
|
22 |
for translated in split_sentences(result.text)[:-1]:
|
23 |
+
sentences.append(paraphrase(adequacy, fluency, translated))
|
24 |
|
25 |
text = '. '.join(list(map(lambda x: x.capitalize(), sentences))) + '.'
|
26 |
if result.detected_source_lang == 'EN':
|