mohmmed5787 commited on
Commit
4c1f7df
·
verified ·
1 Parent(s): 1ff7212

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -0
app.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import pandas as pd
4
+ import random
5
+
6
+ headers = {"User-Agent": "Mozilla/5.0"}
7
+
8
+ # Google Autocomplete Count
9
+ def google_suggest_count(keyword, country):
10
+ try:
11
+ url = f"https://suggestqueries.google.com/complete/search?client=firefox&hl={country}&q={keyword}"
12
+ res = requests.get(url, headers=headers, timeout=10).json()
13
+ return len(res[1])
14
+ except:
15
+ return 0
16
+
17
+ # YouTube Autocomplete Count
18
+ def youtube_suggest_count(keyword, country):
19
+ try:
20
+ url = f"https://suggestqueries.google.com/complete/search?client=firefox&hl={country}&ds=yt&q={keyword}"
21
+ res = requests.get(url, headers=headers, timeout=10).json()
22
+ return len(res[1])
23
+ except:
24
+ return 0
25
+
26
+ def estimate_google_volume(keyword, country):
27
+ suggest = google_suggest_count(keyword, country)
28
+ base = random.randint(500, 5000)
29
+ volume = (suggest * 400) + base
30
+ return int(volume)
31
+
32
+ def estimate_youtube_volume(keyword, country):
33
+ suggest = youtube_suggest_count(keyword, country)
34
+ base = random.randint(1000, 10000)
35
+ volume = (suggest * 300) + base
36
+ return int(volume)
37
+
38
+ def competition_level(volume):
39
+ if volume < 5000:
40
+ return "Low"
41
+ elif volume < 20000:
42
+ return "Medium"
43
+ else:
44
+ return "High"
45
+
46
+ # Main analysis
47
+ def analyze_keywords(keywords_text, country, language, category):
48
+ keywords = [k.strip() for k in keywords_text.split("\n") if k.strip()]
49
+ data = []
50
+ for kw in keywords:
51
+ g_vol = estimate_google_volume(kw, country)
52
+ yt_vol = estimate_youtube_volume(kw, country)
53
+ data.append({
54
+ "Keyword": kw,
55
+ "Country": country,
56
+ "Language": language,
57
+ "Google Monthly Searches": g_vol,
58
+ "YouTube Monthly Searches": yt_vol,
59
+ "Category": category if category else "General",
60
+ "Competition": competition_level(g_vol),
61
+ })
62
+ df = pd.DataFrame(data)
63
+ return df
64
+
65
+ # Gradio UI
66
+ countries = ["US", "EG", "SA", "AE", "GB", "FR", "DE", "ALL"] # يمكنك إضافة كل الدول
67
+ languages = ["English", "Arabic"]
68
+ categories = ["", "Technology", "Education", "Sports", "Health", "Finance"]
69
+
70
+ with gr.Blocks(theme=gr.themes.Soft(), title="Keyword Research Dashboard") as app:
71
+ gr.Markdown("# 🔎 Global Keyword Research Dashboard (Google + YouTube)")
72
+ gr.Markdown("Multi-country, multi-language keyword analysis without API keys")
73
+
74
+ with gr.Row():
75
+ keywords_input = gr.Textbox(
76
+ label="Enter Keywords (One per line)",
77
+ lines=10,
78
+ placeholder="example:\nseo tools\nmake money online\nyoutube automation"
79
+ )
80
+
81
+ with gr.Row():
82
+ country_input = gr.Dropdown(countries, value="ALL", label="Select Country")
83
+ language_input = gr.Dropdown(languages, value="English", label="Select Language")
84
+ category_input = gr.Dropdown(categories, value="", label="Optional Category")
85
+
86
+ analyze_btn = gr.Button("Analyze Keywords", variant="primary")
87
+
88
+ output_table = gr.Dataframe(
89
+ headers=["Keyword","Country","Language","Google Monthly Searches","YouTube Monthly Searches","Category","Competition"],
90
+ interactive=False
91
+ )
92
+
93
+ analyze_btn.click(
94
+ fn=analyze_keywords,
95
+ inputs=[keywords_input, country_input, language_input, category_input],
96
+ outputs=output_table
97
+ )
98
+
99
+ app.launch()