mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
Add article summarization example, closes #144
This commit is contained in:
@@ -137,6 +137,7 @@ Series of example applications with txtai. Links to hosted versions on [Hugging
|
||||
| [Basic similarity search](https://github.com/neuml/txtai/blob/master/examples/similarity.py) | Basic similarity search example. Data from the original txtai demo. |[🤗](https://hf.co/spaces/NeuML/similarity)|
|
||||
| [Book search](https://github.com/neuml/txtai/blob/master/examples/books.py) | Book similarity search application. Index book descriptions and query using natural language statements. |*Local run only*|
|
||||
| [Image search](https://github.com/neuml/txtai/blob/master/examples/images.py) | Image similarity search application. Index a directory of images and run searches to identify images similar to the input query. |[🤗](https://hf.co/spaces/NeuML/imagesearch)|
|
||||
| [Summarize an article](https://github.com/neuml/txtai/blob/master/examples/article.py) | Summarize an article. Workflow that extracts text from a webpage and builds a summary. |[🤗](https://hf.co/spaces/NeuML/articlesummary)|
|
||||
| [Wiki search](https://github.com/neuml/txtai/blob/master/examples/wiki.py) | Wikipedia search application. Queries Wikipedia API and summarizes the top result. |[🤗](https://hf.co/spaces/NeuML/wikisummary)|
|
||||
| [Workflow builder](https://github.com/neuml/txtai/blob/master/examples/workflows.py) | Build and execute txtai workflows. Connect summarization, text extraction, transcription, translation and similarity search pipelines together to run unified workflows. |[🤗](https://hf.co/spaces/NeuML/txtai)|
|
||||
|
||||
|
||||
@@ -54,5 +54,6 @@ Series of example applications with txtai. Links to hosted versions on [Hugging
|
||||
| [Basic similarity search](https://github.com/neuml/txtai/blob/master/examples/similarity.py) | Basic similarity search example. Data from the original txtai demo. |[🤗](https://hf.co/spaces/NeuML/similarity)|
|
||||
| [Book search](https://github.com/neuml/txtai/blob/master/examples/books.py) | Book similarity search application. Index book descriptions and query using natural language statements. |*Local run only*|
|
||||
| [Image search](https://github.com/neuml/txtai/blob/master/examples/images.py) | Image similarity search application. Index a directory of images and run searches to identify images similar to the input query. |[🤗](https://hf.co/spaces/NeuML/imagesearch)|
|
||||
| [Summarize an article](https://github.com/neuml/txtai/blob/master/examples/article.py) | Summarize an article. Workflow that extracts text from a webpage and builds a summary. |[🤗](https://hf.co/spaces/NeuML/articlesummary)|
|
||||
| [Wiki search](https://github.com/neuml/txtai/blob/master/examples/wiki.py) | Wikipedia search application. Queries Wikipedia API and summarizes the top result. |[🤗](https://hf.co/spaces/NeuML/wikisummary)|
|
||||
| [Workflow builder](https://github.com/neuml/txtai/blob/master/examples/workflows.py) | Build and execute txtai workflows. Connect summarization, text extraction, transcription, translation and similarity search pipelines together to run unified workflows. |[🤗](https://hf.co/spaces/NeuML/txtai)|
|
||||
|
||||
@@ -0,0 +1,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()
|
||||
Reference in New Issue
Block a user