Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
from fastai.text.all import *
|
3 |
-
from blurr.text.
|
|
|
|
|
|
|
4 |
|
5 |
-
# Load the
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
return summary
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
iface = gr.Interface(
|
14 |
-
fn=
|
15 |
inputs="text",
|
16 |
outputs="text",
|
17 |
-
title="Article Summarizer",
|
18 |
description="Enter an article and get a summary.",
|
19 |
-
examples=[
|
20 |
-
["Text of an article goes here..."]
|
21 |
-
]
|
22 |
)
|
23 |
|
24 |
-
#
|
25 |
-
squad_metric = load("squad")
|
26 |
-
|
27 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.text.all import *
|
3 |
+
from blurr.text.data.all import *
|
4 |
+
from blurr.text.modeling.all import *
|
5 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
6 |
+
from transformers import BartForConditionalGeneration
|
7 |
|
8 |
+
# Load the pre-trained model and tokenizer
|
9 |
+
pretrained_model_name = "facebook/bart-large-cnn"
|
10 |
+
hf_tokenizer = T5Tokenizer.from_pretrained(pretrained_model_name)
|
11 |
+
learn = load_learner('article_highlights_part3.pkl')
|
12 |
|
13 |
+
def summarize(article):
|
14 |
+
# Preprocess the input text
|
15 |
+
processed_text = learn.dblock.pipeline(article)
|
|
|
16 |
|
17 |
+
# Generate the summary
|
18 |
+
summary = learn.predict(processed_text)[0]['highlights']
|
19 |
+
|
20 |
+
return summary
|
21 |
+
|
22 |
+
# Create the Gradio interface
|
23 |
iface = gr.Interface(
|
24 |
+
fn=summarize,
|
25 |
inputs="text",
|
26 |
outputs="text",
|
27 |
+
title="Article Summarizer (Part 3)",
|
28 |
description="Enter an article and get a summary.",
|
29 |
+
examples=[["This is an example article..."]]
|
|
|
|
|
30 |
)
|
31 |
|
32 |
+
# Launch the Gradio interface
|
|
|
|
|
33 |
iface.launch()
|