Besimplestudio commited on
Commit
b89187a
·
verified ·
1 Parent(s): 6533f22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -9,10 +9,18 @@ def analyze_coloring_trends(search_query='adult coloring books', region='US'):
9
  # Initialize Google Trends connection
10
  pytrends = TrendReq(hl='en-US', tz=360)
11
 
12
- # Define a list of predefined categories (if user doesn't enter a custom query)
13
- if search_query.lower() in ['adult coloring books', 'mandala coloring', 'animal coloring', 'flower coloring', 'kids coloring books']:
 
 
 
 
 
 
 
14
  coloring_categories = [search_query]
15
  else:
 
16
  coloring_categories = [search_query]
17
 
18
  trending_keywords = defaultdict(int)
@@ -54,9 +62,8 @@ def analyze_coloring_trends(search_query='adult coloring books', region='US'):
54
  # Create DataFrame from results
55
  df = pd.DataFrame(results)
56
 
57
- # Check if DataFrame has any data
58
  if df.empty:
59
- print("No data was retrieved.")
60
  return "No data available for the selected category in this region.", "", ""
61
 
62
  # Create bar chart visualization
 
9
  # Initialize Google Trends connection
10
  pytrends = TrendReq(hl='en-US', tz=360)
11
 
12
+ # Predefined categories for the search query
13
+ predefined_categories = [
14
+ 'adult coloring books', 'mandala coloring',
15
+ 'animal coloring', 'flower coloring',
16
+ 'kids coloring books'
17
+ ]
18
+
19
+ # If the search query matches one of the predefined categories, use it
20
+ if search_query.lower() in predefined_categories:
21
  coloring_categories = [search_query]
22
  else:
23
+ # Otherwise, use the user-provided search term as a custom query
24
  coloring_categories = [search_query]
25
 
26
  trending_keywords = defaultdict(int)
 
62
  # Create DataFrame from results
63
  df = pd.DataFrame(results)
64
 
65
+ # If DataFrame is empty, handle the case gracefully
66
  if df.empty:
 
67
  return "No data available for the selected category in this region.", "", ""
68
 
69
  # Create bar chart visualization