yashm commited on
Commit
d8b6c59
·
verified ·
1 Parent(s): 7fee822

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -29,39 +29,41 @@ pytrends = TrendReq(hl='en-US', tz=360)
29
 
30
  st.title('Google Trends Analyzer')
31
 
32
- # Input for multiple keywords
33
- keywords = st.text_input('Enter keywords to analyze (comma-separated):', 'Streamlit, Data Science')
 
34
 
35
- # Geographical focus
36
- geo = st.text_input('Enter geographical region (e.g., US, FR, TH):', '')
 
 
37
 
38
- # Time range selection
39
- timeframe = st.selectbox('Select Time Range:',
40
- ['today 12-m', 'today 3-m', 'today 1-m', 'today 5-y', 'all'])
41
 
42
- # Category selection
43
- category = st.text_input('Enter category number (default is 0):', '0')
 
44
 
45
- # Data Source selection
46
- data_source = st.selectbox('Select Data Source:',
47
- ['Web Search', 'Image Search', 'News Search', 'Google Shopping', 'YouTube Search'])
48
 
49
- if keywords:
50
  # Prepare the keywords list
51
- kw_list = [kw.strip() for kw in keywords.split(',')]
52
-
53
  # Convert data source to pytrends parameter
54
  gprop_map = {
55
  'Web Search': '',
56
  'Image Search': 'images',
57
- 'News Search': 'news',
58
- 'Google Shopping': 'froogle',
59
  'YouTube Search': 'youtube'
60
  }
61
  gprop = gprop_map[data_source]
62
 
63
  # Fetch data from Google Trends
64
- pytrends.build_payload(kw_list, cat=int(category), timeframe=timeframe, geo=geo, gprop=gprop)
65
  interest_over_time_df = pytrends.interest_over_time()
66
 
67
  if not interest_over_time_df.empty:
 
29
 
30
  st.title('Google Trends Analyzer')
31
 
32
+ # Sidebar for options
33
+ with st.sidebar:
34
+ st.header('Analysis Options')
35
 
36
+ # Input for multiple keywords as separate text boxes
37
+ keyword1 = st.text_input('Enter first keyword to analyze:', 'Streamlit')
38
+ keyword2 = st.text_input('Enter second keyword to analyze (optional):', '')
39
+ keyword3 = st.text_input('Enter third keyword to analyze (optional):', '')
40
 
41
+ # Geographical focus dropdown
42
+ countries = ['US', 'FR', 'TH', 'DE', 'IN', 'JP', 'BR', 'GB', 'CA', 'AU']
43
+ geo = st.selectbox('Select geographical region:', countries)
44
 
45
+ # Time range selection
46
+ timeframes = ['now 1-H', 'now 5-H', 'now 1-d', 'now 7-d', 'today 1-m', 'today 3-m']
47
+ timeframe = st.selectbox('Select Time Range:', timeframes)
48
 
49
+ # Data Source selection limited to specific options
50
+ data_source = st.selectbox('Select Data Source:',
51
+ ['Web Search', 'Image Search', 'YouTube Search'])
52
 
53
+ if keyword1 or keyword2 or keyword3:
54
  # Prepare the keywords list
55
+ kw_list = [kw.strip() for kw in [keyword1, keyword2, keyword3] if kw]
56
+
57
  # Convert data source to pytrends parameter
58
  gprop_map = {
59
  'Web Search': '',
60
  'Image Search': 'images',
 
 
61
  'YouTube Search': 'youtube'
62
  }
63
  gprop = gprop_map[data_source]
64
 
65
  # Fetch data from Google Trends
66
+ pytrends.build_payload(kw_list, cat=0, timeframe=timeframe, geo=geo, gprop=gprop)
67
  interest_over_time_df = pytrends.interest_over_time()
68
 
69
  if not interest_over_time_df.empty: