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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -5,17 +5,16 @@ from collections import defaultdict
5
  import plotly.express as px
6
  import time
7
 
8
- def analyze_coloring_trends(region='US'):
9
  # Initialize Google Trends connection
10
  pytrends = TrendReq(hl='en-US', tz=360)
11
 
12
- # Define categories to analyze
13
- coloring_categories = [
14
- 'adult coloring books', 'mandala coloring',
15
- 'animal coloring', 'flower coloring',
16
- 'kids coloring books'
17
- ]
18
-
19
  trending_keywords = defaultdict(int)
20
  results = []
21
 
@@ -58,7 +57,7 @@ def analyze_coloring_trends(region='US'):
58
  # Check if DataFrame has any data
59
  if df.empty:
60
  print("No data was retrieved.")
61
- return "No data available for the selected categories in this region.", "", ""
62
 
63
  # Create bar chart visualization
64
  fig = px.bar(
@@ -79,8 +78,6 @@ def analyze_coloring_trends(region='US'):
79
  recommendations = f"""
80
  Top Trending Categories in {region}:
81
  1. {coloring_categories[0]}
82
- 2. {coloring_categories[1]}
83
- 3. {coloring_categories[2]}
84
 
85
  Recommended Actions:
86
  - Focus on these trending keywords
@@ -91,14 +88,19 @@ def analyze_coloring_trends(region='US'):
91
 
92
  return fig, top_keywords_str, recommendations
93
 
94
- # Create Gradio interface with a refined list of supported regions
95
  iface = gr.Interface(
96
  fn=analyze_coloring_trends,
97
  inputs=[
 
 
 
 
 
98
  gr.Dropdown(
99
  choices=['US', 'UK', 'CA', 'AU', 'DE', 'FR', 'ES', 'IT', 'JP', 'BR', 'IN'],
100
  label="Select Region",
101
- value="US" # Set default region using 'value'
102
  )
103
  ],
104
  outputs=[
 
5
  import plotly.express as px
6
  import time
7
 
8
+ 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)
19
  results = []
20
 
 
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
63
  fig = px.bar(
 
78
  recommendations = f"""
79
  Top Trending Categories in {region}:
80
  1. {coloring_categories[0]}
 
 
81
 
82
  Recommended Actions:
83
  - Focus on these trending keywords
 
88
 
89
  return fig, top_keywords_str, recommendations
90
 
91
+ # Create Gradio interface with search bar
92
  iface = gr.Interface(
93
  fn=analyze_coloring_trends,
94
  inputs=[
95
+ gr.Textbox(
96
+ label="Enter Search Term",
97
+ value="adult coloring books", # Default search term
98
+ placeholder="e.g. adult coloring books, animal coloring, etc."
99
+ ),
100
  gr.Dropdown(
101
  choices=['US', 'UK', 'CA', 'AU', 'DE', 'FR', 'ES', 'IT', 'JP', 'BR', 'IN'],
102
  label="Select Region",
103
+ value="US" # Set default region
104
  )
105
  ],
106
  outputs=[