Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ from transformers import pipeline
|
|
| 3 |
|
| 4 |
# Load NLP pipelines
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
-
paraphraser = pipeline("text2text-generation", model="Vamsi/T5_Paraphrase_Paws")
|
| 7 |
en_to_fil_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-tl")
|
| 8 |
fil_to_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-tl-en")
|
| 9 |
grammar_corrector = pipeline("text2text-generation", model="prithivida/grammar_error_correcter_v1")
|
|
@@ -14,12 +13,9 @@ def process_text(text, task):
|
|
| 14 |
|
| 15 |
try:
|
| 16 |
if task == "Summarize":
|
| 17 |
-
summary = summarizer(text, max_length=
|
| 18 |
return summary[0]['summary_text']
|
| 19 |
|
| 20 |
-
elif task == "Paraphrase":
|
| 21 |
-
return paraphraser(text)[0]['generated_text']
|
| 22 |
-
|
| 23 |
elif task == "Translate English to Filipino":
|
| 24 |
return en_to_fil_translator(text)[0]['translation_text']
|
| 25 |
|
|
@@ -27,7 +23,7 @@ def process_text(text, task):
|
|
| 27 |
return fil_to_en_translator(text)[0]['translation_text']
|
| 28 |
|
| 29 |
elif task == "Grammar & Spell Check":
|
| 30 |
-
corrected = grammar_corrector(f"gec: {text}")
|
| 31 |
return corrected[0]['generated_text']
|
| 32 |
|
| 33 |
else:
|
|
@@ -41,7 +37,6 @@ iface = gr.Interface(
|
|
| 41 |
gr.Textbox(lines=10, placeholder="Paste your text here..."),
|
| 42 |
gr.Dropdown([
|
| 43 |
"Summarize",
|
| 44 |
-
"Paraphrase",
|
| 45 |
"Translate English to Filipino",
|
| 46 |
"Translate Filipino to English",
|
| 47 |
"Grammar & Spell Check"
|
|
@@ -49,7 +44,7 @@ iface = gr.Interface(
|
|
| 49 |
],
|
| 50 |
outputs="text",
|
| 51 |
title="Smart Text Assistant",
|
| 52 |
-
description="Use NLP to summarize,
|
| 53 |
)
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
|
|
|
| 3 |
|
| 4 |
# Load NLP pipelines
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
|
| 6 |
en_to_fil_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-tl")
|
| 7 |
fil_to_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-tl-en")
|
| 8 |
grammar_corrector = pipeline("text2text-generation", model="prithivida/grammar_error_correcter_v1")
|
|
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
if task == "Summarize":
|
| 16 |
+
summary = summarizer(text, max_length=512, min_length=30, do_sample=False)
|
| 17 |
return summary[0]['summary_text']
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
elif task == "Translate English to Filipino":
|
| 20 |
return en_to_fil_translator(text)[0]['translation_text']
|
| 21 |
|
|
|
|
| 23 |
return fil_to_en_translator(text)[0]['translation_text']
|
| 24 |
|
| 25 |
elif task == "Grammar & Spell Check":
|
| 26 |
+
corrected = grammar_corrector(f"gec: {text}", max_length=512, min_length=30, do_sample=False)
|
| 27 |
return corrected[0]['generated_text']
|
| 28 |
|
| 29 |
else:
|
|
|
|
| 37 |
gr.Textbox(lines=10, placeholder="Paste your text here..."),
|
| 38 |
gr.Dropdown([
|
| 39 |
"Summarize",
|
|
|
|
| 40 |
"Translate English to Filipino",
|
| 41 |
"Translate Filipino to English",
|
| 42 |
"Grammar & Spell Check"
|
|
|
|
| 44 |
],
|
| 45 |
outputs="text",
|
| 46 |
title="Smart Text Assistant",
|
| 47 |
+
description="Use NLP to summarize, translate (English ↔ Filipino), and correct grammar and spelling."
|
| 48 |
)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|