Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
-
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, GenerationConfig
|
2 |
-
import gradio as gr
|
3 |
-
|
4 |
-
# Load model
|
5 |
-
tokenizer = AutoTokenizer.from_pretrained('/
|
6 |
-
model = AutoModelForSeq2SeqLM.from_pretrained('/
|
7 |
-
tokenizer.model_max_length = 1024
|
8 |
-
|
9 |
-
# Config
|
10 |
-
gen_config = GenerationConfig(
|
11 |
-
max_length=150,
|
12 |
-
min_length=40,
|
13 |
-
length_penalty=2.0,
|
14 |
-
num_beams=4,
|
15 |
-
early_stopping=True
|
16 |
-
)
|
17 |
-
|
18 |
-
# Summarization function
|
19 |
-
def summarize(blog_post):
|
20 |
-
input = tokenizer(blog_post, max_length=1024, truncation=True, return_tensors='pt')
|
21 |
-
summary_ids = model.generate(input['input_ids'], generation_config=gen_config)
|
22 |
-
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
23 |
-
return summary
|
24 |
-
|
25 |
-
# Gradio UI
|
26 |
-
iface = gr.Interface(
|
27 |
-
fn=summarize,
|
28 |
-
inputs=gr.Textbox(lines=15, label="Enter Text to Summarize"),
|
29 |
-
outputs=gr.Textbox(label="Summary"),
|
30 |
-
title="Text Summarizer",
|
31 |
-
description="Enter a long paragraph or blog post to get a summarized version."
|
32 |
-
)
|
33 |
-
|
34 |
-
iface.launch(share=True)
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, GenerationConfig
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load model
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained('AyushSoni14/text-summarizer-model')
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained('AyushSoni14/text-summarizer-model')
|
7 |
+
tokenizer.model_max_length = 1024
|
8 |
+
|
9 |
+
# Config
|
10 |
+
gen_config = GenerationConfig(
|
11 |
+
max_length=150,
|
12 |
+
min_length=40,
|
13 |
+
length_penalty=2.0,
|
14 |
+
num_beams=4,
|
15 |
+
early_stopping=True
|
16 |
+
)
|
17 |
+
|
18 |
+
# Summarization function
|
19 |
+
def summarize(blog_post):
|
20 |
+
input = tokenizer(blog_post, max_length=1024, truncation=True, return_tensors='pt')
|
21 |
+
summary_ids = model.generate(input['input_ids'], generation_config=gen_config)
|
22 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
23 |
+
return summary
|
24 |
+
|
25 |
+
# Gradio UI
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=summarize,
|
28 |
+
inputs=gr.Textbox(lines=15, label="Enter Text to Summarize"),
|
29 |
+
outputs=gr.Textbox(label="Summary"),
|
30 |
+
title="Text Summarizer",
|
31 |
+
description="Enter a long paragraph or blog post to get a summarized version."
|
32 |
+
)
|
33 |
+
|
34 |
+
iface.launch(share=True)
|