jarif commited on
Commit
89a4135
1 Parent(s): 8a2f6f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -1,27 +1,33 @@
1
  import gradio as gr
2
  from fastai.text.all import *
3
- from blurr.text.modeling.all import load
 
 
 
4
 
5
- # Load the exported model
6
- learn = load_learner('article_highlights.pkl')
 
 
7
 
8
- def generate_summary(article_text):
9
- # Perform inference using the loaded model
10
- summary = learn.blurr_generate_summary(article_text)
11
- return summary
12
 
 
 
 
 
 
 
13
  iface = gr.Interface(
14
- fn=generate_summary,
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
- # Update: Use load from the evaluate library
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()