-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit.py
More file actions
63 lines (50 loc) · 2.53 KB
/
Copy pathstreamlit.py
File metadata and controls
63 lines (50 loc) · 2.53 KB
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
import streamlit as st
import pandas as pd
from cryptosentiment import crypto_categorizer, get_sentiment
from summarizer import summarize_news_article
from combiner import combinedscraperfunc
def safe_lower(value):
try:
return str(value).lower()
except:
return ""
def main():
st.set_page_config(page_title="Crypto News Analyzer", page_icon=":newspaper:", layout="wide")
st.title("Crypto News Analyzer")
# Button in the sidebar to trigger the scraper function
if st.sidebar.button("Fetch Latest News"):
with st.spinner('Fetching latest news...'):
combinedscraperfunc() # Run the scraping function
st.sidebar.success("News data updated!")
# Read the CSV file directly
news_data = pd.read_csv("cryptocurrency_newsapi.csv")
st.sidebar.title("Filters")
search_term = st.sidebar.text_input("Search news")
for index, row in news_data.iterrows():
title = safe_lower(row.get('title', ''))
description = safe_lower(row.get('description', ''))
if search_term.lower() in title or search_term.lower() in description:
col1, col2 = st.columns([3, 1])
with col1:
if st.button(f"📰 {row.get('title', 'Untitled')}", key=f"news_{index}"):
with st.expander("Article Details", expanded=True):
st.write(f"**Source:** {row.get('source', 'Unknown')}")
st.write(f"**Published:** {row.get('date', 'Unknown')}")
st.write(f"**Link:** {row.get('url', 'No description available')}")
sentiment = str(row.get('sentiment', ''))
content = str(row.get('body', ''))
if len(content) > 20000:
content = content[:20000] + "..."
summarized_content = summarize_news_article(content)
categories = crypto_categorizer(content)
get_sentiment(summarized_content, sentiment, categories)
st.write("**Cryptocurrencies mentioned:**")
for category in categories:
st.write("- " + category)
with col2:
image_url = row.get('image')
if image_url and isinstance(image_url, str):
st.image(image_url, use_column_width=True)
st.markdown("---")
if __name__ == "__main__":
main()