Jonas Neves
commited on
Commit
Β·
eabeab3
1
Parent(s):
a5f2bf9
Move hardcoded data to config.json
Browse files- config.json +32 -0
- src/api_handler.py +8 -5
- src/streamlit_app.py +18 -24
config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"search_queries": [
|
| 3 |
+
"artificial intelligence",
|
| 4 |
+
"machine learning",
|
| 5 |
+
"ChatGPT",
|
| 6 |
+
"OpenAI",
|
| 7 |
+
"deep learning",
|
| 8 |
+
"neural networks",
|
| 9 |
+
"AI ethics",
|
| 10 |
+
"robotics",
|
| 11 |
+
"computer vision",
|
| 12 |
+
"natural language processing"
|
| 13 |
+
],
|
| 14 |
+
"news_sources": {
|
| 15 |
+
"tech_media": "techcrunch,wired,ars-technica,the-verge,engadget",
|
| 16 |
+
"general_news": "reuters,associated-press,bbc-news",
|
| 17 |
+
"us_news": "cnn,fox-news,abc-news",
|
| 18 |
+
"financial_news": "financial-times,wall-street-journal,bloomberg"
|
| 19 |
+
},
|
| 20 |
+
"source_categories": [
|
| 21 |
+
"All Sources",
|
| 22 |
+
"Tech Media",
|
| 23 |
+
"General News",
|
| 24 |
+
"US News",
|
| 25 |
+
"Financial News"
|
| 26 |
+
],
|
| 27 |
+
"test_texts": [
|
| 28 |
+
"AI breakthrough promises to revolutionize healthcare",
|
| 29 |
+
"Concerns grow over AI job displacement",
|
| 30 |
+
"New machine learning model shows mixed results"
|
| 31 |
+
]
|
| 32 |
+
}
|
src/api_handler.py
CHANGED
|
@@ -6,6 +6,7 @@ import requests
|
|
| 6 |
import pandas as pd
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
import os
|
|
|
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
from textblob import TextBlob
|
| 11 |
from typing import List, Dict, Optional
|
|
@@ -226,19 +227,21 @@ def get_ai_news_with_sentiment(query="artificial intelligence", days=7, sources=
|
|
| 226 |
analyzer = AINewsAnalyzer()
|
| 227 |
return analyzer.get_ai_news_with_sentiment(query, days, sources)
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
if __name__ == "__main__":
|
| 230 |
# Test the API when run directly
|
| 231 |
analyzer = AINewsAnalyzer()
|
|
|
|
| 232 |
|
| 233 |
print("Testing AI News Sentiment Analyzer...")
|
| 234 |
print("=" * 50)
|
| 235 |
|
| 236 |
# Test sentiment analysis
|
| 237 |
-
test_texts = [
|
| 238 |
-
"AI breakthrough promises to revolutionize healthcare",
|
| 239 |
-
"Concerns grow over AI job displacement",
|
| 240 |
-
"New machine learning model shows mixed results"
|
| 241 |
-
]
|
| 242 |
|
| 243 |
print("\nSentiment Analysis Examples:")
|
| 244 |
for text in test_texts:
|
|
|
|
| 6 |
import pandas as pd
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
import os
|
| 9 |
+
import json
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from textblob import TextBlob
|
| 12 |
from typing import List, Dict, Optional
|
|
|
|
| 227 |
analyzer = AINewsAnalyzer()
|
| 228 |
return analyzer.get_ai_news_with_sentiment(query, days, sources)
|
| 229 |
|
| 230 |
+
def load_config():
|
| 231 |
+
"""Load configuration from config.json"""
|
| 232 |
+
with open('config.json', 'r') as f:
|
| 233 |
+
return json.load(f)
|
| 234 |
+
|
| 235 |
if __name__ == "__main__":
|
| 236 |
# Test the API when run directly
|
| 237 |
analyzer = AINewsAnalyzer()
|
| 238 |
+
config = load_config()
|
| 239 |
|
| 240 |
print("Testing AI News Sentiment Analyzer...")
|
| 241 |
print("=" * 50)
|
| 242 |
|
| 243 |
# Test sentiment analysis
|
| 244 |
+
test_texts = config["test_texts"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
print("\nSentiment Analysis Examples:")
|
| 247 |
for text in test_texts:
|
src/streamlit_app.py
CHANGED
|
@@ -6,6 +6,7 @@ Interactive dashboard for analyzing sentiment of AI-related news
|
|
| 6 |
import streamlit as st
|
| 7 |
import pandas as pd
|
| 8 |
import plotly.express as px
|
|
|
|
| 9 |
from api_handler import AINewsAnalyzer
|
| 10 |
|
| 11 |
# Page configuration
|
|
@@ -38,6 +39,12 @@ st.markdown("""
|
|
| 38 |
</style>
|
| 39 |
""", unsafe_allow_html=True)
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
@st.cache_data(ttl=1800) # Cache for 30 minutes
|
| 42 |
def load_news_data(query, days, sources=None):
|
| 43 |
"""Load and cache news data"""
|
|
@@ -124,22 +131,14 @@ def main():
|
|
| 124 |
st.markdown("<h1 class='main-header'>π€ AI News Sentiment Analyzer</h1>", unsafe_allow_html=True)
|
| 125 |
st.markdown("### Discover the sentiment trends in AI-related news from around the world")
|
| 126 |
|
|
|
|
|
|
|
|
|
|
| 127 |
# Sidebar controls
|
| 128 |
st.sidebar.header("π§ Analysis Settings")
|
| 129 |
|
| 130 |
# Query input
|
| 131 |
-
query_options = [
|
| 132 |
-
"artificial intelligence",
|
| 133 |
-
"machine learning",
|
| 134 |
-
"ChatGPT",
|
| 135 |
-
"OpenAI",
|
| 136 |
-
"deep learning",
|
| 137 |
-
"neural networks",
|
| 138 |
-
"AI ethics",
|
| 139 |
-
"robotics",
|
| 140 |
-
"computer vision",
|
| 141 |
-
"natural language processing"
|
| 142 |
-
]
|
| 143 |
|
| 144 |
selected_query = st.sidebar.selectbox(
|
| 145 |
"π Search Topic:",
|
|
@@ -164,28 +163,23 @@ def main():
|
|
| 164 |
help="How many days back to search for news"
|
| 165 |
)
|
| 166 |
|
| 167 |
-
# News sources
|
| 168 |
-
|
| 169 |
-
"techcrunch,wired,ars-technica,the-verge,engadget",
|
| 170 |
-
"reuters,associated-press,bbc-news",
|
| 171 |
-
"cnn,fox-news,abc-news",
|
| 172 |
-
"financial-times,wall-street-journal,bloomberg"
|
| 173 |
-
]
|
| 174 |
|
| 175 |
source_option = st.sidebar.selectbox(
|
| 176 |
"π° Source Category:",
|
| 177 |
-
options=["
|
| 178 |
index=0
|
| 179 |
)
|
| 180 |
|
| 181 |
if source_option == "Tech Media":
|
| 182 |
-
sources =
|
| 183 |
elif source_option == "General News":
|
| 184 |
-
sources =
|
| 185 |
elif source_option == "US News":
|
| 186 |
-
sources =
|
| 187 |
elif source_option == "Financial News":
|
| 188 |
-
sources =
|
| 189 |
else:
|
| 190 |
sources = None
|
| 191 |
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
import pandas as pd
|
| 8 |
import plotly.express as px
|
| 9 |
+
import json
|
| 10 |
from api_handler import AINewsAnalyzer
|
| 11 |
|
| 12 |
# Page configuration
|
|
|
|
| 39 |
</style>
|
| 40 |
""", unsafe_allow_html=True)
|
| 41 |
|
| 42 |
+
@st.cache_data(ttl=1800) # Cache for 30 minutes
|
| 43 |
+
def load_config():
|
| 44 |
+
"""Load configuration from config.json"""
|
| 45 |
+
with open('config.json', 'r') as f:
|
| 46 |
+
return json.load(f)
|
| 47 |
+
|
| 48 |
@st.cache_data(ttl=1800) # Cache for 30 minutes
|
| 49 |
def load_news_data(query, days, sources=None):
|
| 50 |
"""Load and cache news data"""
|
|
|
|
| 131 |
st.markdown("<h1 class='main-header'>π€ AI News Sentiment Analyzer</h1>", unsafe_allow_html=True)
|
| 132 |
st.markdown("### Discover the sentiment trends in AI-related news from around the world")
|
| 133 |
|
| 134 |
+
# Load configuration
|
| 135 |
+
config = load_config()
|
| 136 |
+
|
| 137 |
# Sidebar controls
|
| 138 |
st.sidebar.header("π§ Analysis Settings")
|
| 139 |
|
| 140 |
# Query input
|
| 141 |
+
query_options = config["search_queries"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
selected_query = st.sidebar.selectbox(
|
| 144 |
"π Search Topic:",
|
|
|
|
| 163 |
help="How many days back to search for news"
|
| 164 |
)
|
| 165 |
|
| 166 |
+
# News sources from config
|
| 167 |
+
news_sources = config["news_sources"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
source_option = st.sidebar.selectbox(
|
| 170 |
"π° Source Category:",
|
| 171 |
+
options=config["source_categories"],
|
| 172 |
index=0
|
| 173 |
)
|
| 174 |
|
| 175 |
if source_option == "Tech Media":
|
| 176 |
+
sources = news_sources["tech_media"]
|
| 177 |
elif source_option == "General News":
|
| 178 |
+
sources = news_sources["general_news"]
|
| 179 |
elif source_option == "US News":
|
| 180 |
+
sources = news_sources["us_news"]
|
| 181 |
elif source_option == "Financial News":
|
| 182 |
+
sources = news_sources["financial_news"]
|
| 183 |
else:
|
| 184 |
sources = None
|
| 185 |
|