Commit
·
e875e01
1
Parent(s):
4428e17
Upload 5 files
Browse files- app.py +75 -0
- config.toml +5 -0
- logo.jpg +0 -0
- logo1.jpg +0 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import json
|
3 |
+
import requests
|
4 |
+
from newspaper import Article
|
5 |
+
|
6 |
+
st.set_page_config(page_title='Short News App',
|
7 |
+
layout = 'wide',
|
8 |
+
initial_sidebar_state = 'expanded',
|
9 |
+
menu_items={
|
10 |
+
'About':'This is a demo application with One AI',
|
11 |
+
'Get help':'https://studio.oneai.com/docs',
|
12 |
+
'Report a Bug':'https://discord.com/channels/941458663493746698/941458828187287603'
|
13 |
+
})
|
14 |
+
st.title('Short Summary News Application Demo with OneAI')
|
15 |
+
st.markdown('This application takes an input from the user and displays upto five latest news articles along with their summary. This application uses the free quota api calls.')
|
16 |
+
st.sidebar.image('logo.jpg')
|
17 |
+
st.sidebar.title('ONE AI')
|
18 |
+
st.sidebar.markdown('[One AI](https://www.oneai.com/) is an API-first, language AI service built for developers. Embed your API to analyze, process, and transform text in your project.')
|
19 |
+
st.sidebar.markdown('''It can perform several tasks like
|
20 |
+
- Sentiment Analysis
|
21 |
+
- Named Entity Recognition
|
22 |
+
- Topic Analysis
|
23 |
+
- Text Summarization
|
24 |
+
- Keyword Extraction
|
25 |
+
There are several more tasks that One AI can do. Please find the below links to explore more about this:''')
|
26 |
+
st.sidebar.markdown('[About us](https://www.oneai.com/about-us)')
|
27 |
+
st.sidebar.markdown('[Documentation](https://studio.oneai.com/docs)')
|
28 |
+
st.sidebar.markdown('[Contact](https://www.oneai.com/contact-us)')
|
29 |
+
st.sidebar.markdown('[Community](https://discord.com/channels/941458663493746698/942326235722309642)')
|
30 |
+
st.sidebar.markdown('© 2022 Logo rights reserved to One AI')
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
def run():
|
35 |
+
|
36 |
+
@st.cache()
|
37 |
+
def summary(text1):
|
38 |
+
api_key = "1c93487c-695c-4089-adfc-5e4b7623718c"
|
39 |
+
url = "https://api.oneai.com/api/v0/pipeline"
|
40 |
+
text = text1
|
41 |
+
headers = {'api-key':api_key, 'content-type':'application/json'}
|
42 |
+
payload = {'input':text, 'input_type':'article', 'steps':[{'skill':'summarize'}]}
|
43 |
+
r = requests.post(url, json=payload, headers=headers)
|
44 |
+
data = r.json()
|
45 |
+
return data['output'][0]['text']
|
46 |
+
|
47 |
+
def get_links(text2):
|
48 |
+
url = "https://free-news.p.rapidapi.com/v1/search"
|
49 |
+
querystring = {"q":text2,"lang":"en", "page":1, "page_size":5}
|
50 |
+
headers = {'x-rapidapi-host': "free-news.p.rapidapi.com",'x-rapidapi-key': "375ffbaab0mshb442ffb69d6f025p117ba0jsn01e8146148e3"}
|
51 |
+
response = requests.request("GET", url, headers=headers, params=querystring)
|
52 |
+
response_dict = json.loads(response.text)
|
53 |
+
links = [response_dict['articles'][i]['link'] for i in range(len(response_dict['articles']))]
|
54 |
+
return links
|
55 |
+
|
56 |
+
input_text = st.text_input('Search your favorite topic:')
|
57 |
+
submitted = st.button('Submit')
|
58 |
+
|
59 |
+
if submitted:
|
60 |
+
links = get_links(input_text)
|
61 |
+
for link in links:
|
62 |
+
try:
|
63 |
+
news_article = Article(link, language='en')
|
64 |
+
news_article.download()
|
65 |
+
news_article.parse()
|
66 |
+
st.image(news_article.top_image)
|
67 |
+
st.header(news_article.title)
|
68 |
+
st.markdown('*Summary of the Article:*')
|
69 |
+
st.markdown(summary(news_article.text))
|
70 |
+
with st.expander('Full Article'):
|
71 |
+
st.markdown(news_article.text)
|
72 |
+
except:
|
73 |
+
print('No Results!! Please try with new search!!')
|
74 |
+
if __name__ == '__main__':
|
75 |
+
run()
|
config.toml
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
primaryColor="#0c0c0c"
|
3 |
+
backgroundColor="#f9f9f2"
|
4 |
+
secondaryBackgroundColor="#b7565c"
|
5 |
+
textColor="#0a0a0a"
|
logo.jpg
ADDED
![]() |
logo1.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
newspaper3k
|