dami1996 commited on
Commit
23323a5
β€’
1 Parent(s): dc3659d

Error message if unable to search articles

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +16 -7
README.md CHANGED
@@ -2,7 +2,7 @@
2
  title: Trading Analyst
3
  emoji: πŸ“ˆ
4
  colorFrom: green
5
- colorTo: green
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(asset_name):
29
- logging.info(f"Fetching articles for asset: {asset_name}")
30
- googlenews = GoogleNews(lang="en")
31
- googlenews.search(asset_name)
32
- articles = googlenews.result()
33
- logging.info(f"Fetched {len(articles)} articles")
34
- return articles
 
 
 
 
 
 
 
 
 
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):