Spaces:
Running
Running
Error message if unable to search articles
Browse files
README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
title: Trading Analyst
|
3 |
emoji: π
|
4 |
colorFrom: green
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.39.0
|
8 |
app_file: app.py
|
|
|
2 |
title: Trading Analyst
|
3 |
emoji: π
|
4 |
colorFrom: green
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.39.0
|
8 |
app_file: app.py
|
app.py
CHANGED
@@ -25,13 +25,22 @@ sentiment_analyzer = pipeline(
|
|
25 |
logging.info("Model initialized successfully")
|
26 |
|
27 |
|
28 |
-
def fetch_articles(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
def analyze_article_sentiment(article):
|
|
|
25 |
logging.info("Model initialized successfully")
|
26 |
|
27 |
|
28 |
+
def fetch_articles(query):
|
29 |
+
try:
|
30 |
+
logging.info(f"Fetching articles for query: '{query}'")
|
31 |
+
googlenews = GoogleNews(lang="en")
|
32 |
+
googlenews.search(query)
|
33 |
+
articles = googlenews.result()
|
34 |
+
logging.info(f"Fetched {len(articles)} articles")
|
35 |
+
return articles
|
36 |
+
except Exception as e:
|
37 |
+
logging.error(
|
38 |
+
f"Error while searching articles for query: '{query}'. Error: {e}"
|
39 |
+
)
|
40 |
+
raise gr.Error(
|
41 |
+
f"Unable to search articles for query: '{query}'. Try again later...",
|
42 |
+
duration=5,
|
43 |
+
)
|
44 |
|
45 |
|
46 |
def analyze_article_sentiment(article):
|