File size: 905 Bytes
6e8e738
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import gradio as gr
from transformers import pipeline
import requests
from bs4 import BeautifulSoup



# In[9]:


pipe = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")

def get_abstract(url):
    page = requests.get(url)
    soup = BeautifulSoup(page.content, "html.parser")
    abstract = soup.find(id="eng-abstract").text
    return abstract

def summarize(input):
    abstract = get_abstract(input)
    summary = pipe(abstract)
    return summary[0]["summary_text"]

demo = gr.Interface(
    fn=summarize, 
    inputs=gr.Textbox(placeholder="PubMed URL", label="PubMed URL"), 
    outputs=gr.Textbox(placeholder="Your Summary will appear here", label="Summary"), 
    title="PubMed Summarizer📝",
    examples=["https://pubmed.ncbi.nlm.nih.gov/36258852/", "https://pubmed.ncbi.nlm.nih.gov/34747661/"])

demo.launch()


# In[ ]: