Spaces:
Sleeping
Sleeping
Commit
·
cbb2141
1
Parent(s):
081216f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Application that builds a summary of an article.
|
3 |
+
"""
|
4 |
+
|
5 |
+
import os
|
6 |
+
|
7 |
+
import streamlit as st
|
8 |
+
|
9 |
+
from txtai.pipeline import Summary
|
10 |
+
from txtai.workflow import UrlTask, Task, Workflow
|
11 |
+
|
12 |
+
from textractor import Textractor
|
13 |
+
|
14 |
+
|
15 |
+
class Application:
|
16 |
+
"""
|
17 |
+
Main application.
|
18 |
+
"""
|
19 |
+
|
20 |
+
def __init__(self):
|
21 |
+
"""
|
22 |
+
Creates a new application.
|
23 |
+
"""
|
24 |
+
|
25 |
+
textract = Textractor(paragraphs=True, minlength=100, join=True)
|
26 |
+
summary = Summary("sshleifer/distilbart-cnn-12-6")
|
27 |
+
|
28 |
+
self.workflow = Workflow([UrlTask(textract), Task(summary)])
|
29 |
+
|
30 |
+
def run(self):
|
31 |
+
"""
|
32 |
+
Runs a Streamlit application.
|
33 |
+
"""
|
34 |
+
|
35 |
+
st.title("Article Summary")
|
36 |
+
st.markdown("This application builds a summary of an article.")
|
37 |
+
|
38 |
+
url = st.text_input("URL")
|
39 |
+
if url:
|
40 |
+
# Run workflow and get summary
|
41 |
+
summary = list(self.workflow([url]))[0]
|
42 |
+
|
43 |
+
# Write results
|
44 |
+
st.write(summary)
|
45 |
+
st.markdown("*Source: " + url + "*")
|
46 |
+
|
47 |
+
|
48 |
+
@st.cache(allow_output_mutation=True)
|
49 |
+
def create():
|
50 |
+
"""
|
51 |
+
Creates and caches a Streamlit application.
|
52 |
+
|
53 |
+
Returns:
|
54 |
+
Application
|
55 |
+
"""
|
56 |
+
|
57 |
+
return Application()
|
58 |
+
|
59 |
+
|
60 |
+
if __name__ == "__main__":
|
61 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
62 |
+
|
63 |
+
# Create and run application
|
64 |
+
app = create()
|
65 |
+
app.run()
|