gradsyntax commited on
Commit
47184dd
·
verified ·
1 Parent(s): 495b052

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
+
4
+ # Load models
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
+ summarizer = pipeline("summarization", model=summarizer_model_name)
17
+
18
+ # Define functions
19
+ def polish_abstract(text):
20
+ # Grammar correction
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
+ # Summarization
26
+ summary = summarizer(corrected, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
27
+
28
+ # Title generation
29
+ title_input = "generate title: " + corrected
30
+ title_inputs = title_tokenizer.encode(title_input, return_tensors="pt", max_length=512, truncation=True)
31
+ title_outputs = title_model.generate(title_inputs, max_length=15, num_beams=5, early_stopping=True)
32
+ title = title_tokenizer.decode(title_outputs[0], skip_special_tokens=True)
33
+
34
+ return corrected, summary, title
35
+
36
+ # Gradio Interface
37
+ iface = gr.Interface(
38
+ fn=polish_abstract,
39
+ inputs=gr.Textbox(lines=10, label="Paste Your Raw Abstract Here"),
40
+ outputs=[
41
+ gr.Textbox(label="✅ Corrected Abstract (Grammar Fixed)"),
42
+ gr.Textbox(label="🪄 Polished Summary (Concise Version)"),
43
+ gr.Textbox(label="📘 Suggested Title"),
44
+ ],
45
+ title="🧠 AI Abstract & Title Polisher",
46
+ description="Paste your raw abstract. The AI will fix grammar, generate a concise summary, and suggest a title."
47
+ )
48
+
49
+ iface.launch()