-
Notifications
You must be signed in to change notification settings - Fork 649
/
Copy patharticle.py
66 lines (46 loc) · 1.34 KB
/
article.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Application that builds a summary of an article.
Requires streamlit to be installed.
pip install streamlit
"""
import os
import streamlit as st
from txtai.pipeline import Summary, Textractor
from txtai.workflow import UrlTask, Task, Workflow
class Application:
"""
Main application.
"""
def __init__(self):
"""
Creates a new application.
"""
textract = Textractor(paragraphs=True, minlength=100, join=True)
summary = Summary("sshleifer/distilbart-cnn-12-6")
self.workflow = Workflow([UrlTask(textract), Task(summary)])
def run(self):
"""
Runs a Streamlit application.
"""
st.title("Article Summary")
st.markdown("This application builds a summary of an article.")
url = st.text_input("URL")
if url:
# Run workflow and get summary
summary = list(self.workflow([url]))[0]
# Write results
st.write(summary)
st.markdown("*Source: " + url + "*")
@st.cache(allow_output_mutation=True)
def create():
"""
Creates and caches a Streamlit application.
Returns:
Application
"""
return Application()
if __name__ == "__main__":
os.environ["TOKENIZERS_PARALLELISM"] = "false"
# Create and run application
app = create()
app.run()