Spaces:
Runtime error
Runtime error
rasmus1610
commited on
Commit
•
6e8e738
1
Parent(s):
f995516
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[1]:
|
5 |
+
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
from transformers import pipeline
|
9 |
+
import requests
|
10 |
+
from bs4 import BeautifulSoup
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
# In[9]:
|
15 |
+
|
16 |
+
|
17 |
+
pipe = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
18 |
+
|
19 |
+
def get_abstract(url):
|
20 |
+
page = requests.get(url)
|
21 |
+
soup = BeautifulSoup(page.content, "html.parser")
|
22 |
+
abstract = soup.find(id="eng-abstract").text
|
23 |
+
return abstract
|
24 |
+
|
25 |
+
def summarize(input):
|
26 |
+
abstract = get_abstract(input)
|
27 |
+
summary = pipe(abstract)
|
28 |
+
return summary[0]["summary_text"]
|
29 |
+
|
30 |
+
demo = gr.Interface(
|
31 |
+
fn=summarize,
|
32 |
+
inputs=gr.Textbox(placeholder="PubMed URL", label="PubMed URL"),
|
33 |
+
outputs=gr.Textbox(placeholder="Your Summary will appear here", label="Summary"),
|
34 |
+
title="PubMed Summarizer📝",
|
35 |
+
examples=["https://pubmed.ncbi.nlm.nih.gov/36258852/", "https://pubmed.ncbi.nlm.nih.gov/34747661/"])
|
36 |
+
|
37 |
+
demo.launch()
|
38 |
+
|
39 |
+
|
40 |
+
# In[ ]:
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|