updated
Browse files
app.py
CHANGED
|
@@ -1,37 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
grammar_model_name = "prithivida/grammar_error_correcter_v1"
|
| 6 |
-
summarizer_model_name = "facebook/bart-large-cnn"
|
| 7 |
-
title_model_name = "t5-base"
|
| 8 |
-
|
| 9 |
-
# Load tokenizer and models
|
| 10 |
grammar_tokenizer = AutoTokenizer.from_pretrained(grammar_model_name)
|
| 11 |
grammar_model = AutoModelForSeq2SeqLM.from_pretrained(grammar_model_name)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
title_tokenizer = AutoTokenizer.from_pretrained(title_model_name)
|
| 14 |
title_model = AutoModelForSeq2SeqLM.from_pretrained(title_model_name)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
inputs = grammar_tokenizer.encode("gec: " + text, return_tensors="pt", max_length=512, truncation=True)
|
| 22 |
-
outputs = grammar_model.generate(inputs, max_length=512, num_beams=5, early_stopping=True)
|
| 23 |
-
corrected = grammar_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
# Title
|
| 29 |
-
|
| 30 |
-
title_inputs = title_tokenizer.encode(
|
| 31 |
-
title_outputs = title_model.generate(title_inputs, max_length=
|
| 32 |
-
|
| 33 |
|
| 34 |
-
return
|
| 35 |
|
| 36 |
# Gradio Interface
|
| 37 |
iface = gr.Interface(
|
|
@@ -43,7 +42,7 @@ iface = gr.Interface(
|
|
| 43 |
gr.Textbox(label="📘 Suggested Title"),
|
| 44 |
],
|
| 45 |
title="🧠 AI Abstract & Title Polisher",
|
| 46 |
-
description="Paste your
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 3 |
|
| 4 |
+
# Load grammar model
|
| 5 |
grammar_model_name = "prithivida/grammar_error_correcter_v1"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
grammar_tokenizer = AutoTokenizer.from_pretrained(grammar_model_name)
|
| 7 |
grammar_model = AutoModelForSeq2SeqLM.from_pretrained(grammar_model_name)
|
| 8 |
|
| 9 |
+
# Load summarizer
|
| 10 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 11 |
+
|
| 12 |
+
# Load title generation model
|
| 13 |
+
title_model_name = "t5-base"
|
| 14 |
title_tokenizer = AutoTokenizer.from_pretrained(title_model_name)
|
| 15 |
title_model = AutoModelForSeq2SeqLM.from_pretrained(title_model_name)
|
| 16 |
|
| 17 |
+
def polish_abstract(raw_text):
|
| 18 |
+
# 1. Grammar Correction
|
| 19 |
+
grammar_inputs = grammar_tokenizer.encode("gec: " + raw_text, return_tensors="pt", truncation=True, max_length=512)
|
| 20 |
+
grammar_outputs = grammar_model.generate(grammar_inputs, max_length=512, num_beams=5)
|
| 21 |
+
corrected_text = grammar_tokenizer.decode(grammar_outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# 2. Summary (Concise)
|
| 24 |
+
summary_output = summarizer(corrected_text, max_length=120, min_length=30, do_sample=False)
|
| 25 |
+
summary_text = summary_output[0]['summary_text']
|
| 26 |
|
| 27 |
+
# 3. Title Generation
|
| 28 |
+
title_prompt = "generate title: " + corrected_text
|
| 29 |
+
title_inputs = title_tokenizer.encode(title_prompt, return_tensors="pt", truncation=True, max_length=512)
|
| 30 |
+
title_outputs = title_model.generate(title_inputs, max_length=20, num_beams=5)
|
| 31 |
+
generated_title = title_tokenizer.decode(title_outputs[0], skip_special_tokens=True)
|
| 32 |
|
| 33 |
+
return corrected_text, summary_text, generated_title
|
| 34 |
|
| 35 |
# Gradio Interface
|
| 36 |
iface = gr.Interface(
|
|
|
|
| 42 |
gr.Textbox(label="📘 Suggested Title"),
|
| 43 |
],
|
| 44 |
title="🧠 AI Abstract & Title Polisher",
|
| 45 |
+
description="Paste your rough abstract. This AI tool will correct grammar, generate a concise summary, and suggest a scientific title."
|
| 46 |
)
|
| 47 |
|
| 48 |
iface.launch()
|