seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import requests
|
|
3 |
|
4 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
5 |
|
6 |
-
#
|
7 |
MAJOR_COUNTRIES = [
|
8 |
"United States", "United Kingdom", "Canada", "Australia", "Germany",
|
9 |
"France", "Japan", "South Korea", "China", "India",
|
@@ -17,16 +17,16 @@ MAJOR_COUNTRIES = [
|
|
17 |
"Indonesia", "Philippines", "Vietnam", "Pakistan", "Bangladesh"
|
18 |
]
|
19 |
|
20 |
-
def search_serphouse(query,
|
21 |
url = "https://api.serphouse.com/serp/live"
|
22 |
|
23 |
params = {
|
24 |
"q": query,
|
25 |
-
"domain":
|
26 |
-
"lang":
|
27 |
-
"device":
|
28 |
-
"serp_type":
|
29 |
-
"loc":
|
30 |
"country": country,
|
31 |
"verbatim": verbatim,
|
32 |
"gfilter": gfilter,
|
@@ -47,9 +47,9 @@ def search_serphouse(query, domain, language, device, serp_type, location, count
|
|
47 |
|
48 |
def format_results(results):
|
49 |
if isinstance(results, dict) and "results" in results:
|
50 |
-
|
51 |
formatted_results = ""
|
52 |
-
for i, result in enumerate(
|
53 |
formatted_results += f"{i}. {result['title']}\n"
|
54 |
formatted_results += f" URL: {result['link']}\n"
|
55 |
formatted_results += f" Snippet: {result['snippet']}\n\n"
|
@@ -57,22 +57,17 @@ def format_results(results):
|
|
57 |
else:
|
58 |
return str(results)
|
59 |
|
60 |
-
def serphouse_search(query,
|
61 |
verbatim = "1" if verbatim else "0"
|
62 |
gfilter = "1" if gfilter else "0"
|
63 |
|
64 |
-
results = search_serphouse(query,
|
65 |
return format_results(results)
|
66 |
|
67 |
iface = gr.Interface(
|
68 |
fn=serphouse_search,
|
69 |
inputs=[
|
70 |
gr.Textbox(label="Search Query"),
|
71 |
-
gr.Dropdown(["google.com", "google.co.uk", "google.ca", "google.com.au", "google.de", "google.fr", "google.co.jp", "google.co.kr", "google.com.br", "google.com.mx"], label="Domain"),
|
72 |
-
gr.Dropdown(["en", "de", "fr", "es", "it", "pt", "ru", "ja", "ko", "zh-CN"], label="Language"),
|
73 |
-
gr.Radio(["desktop", "mobile"], label="Device"),
|
74 |
-
gr.Dropdown(["web", "news", "images"], label="SERP Type"),
|
75 |
-
gr.Textbox(label="Location"),
|
76 |
gr.Dropdown(MAJOR_COUNTRIES, label="Country"),
|
77 |
gr.Checkbox(label="Verbatim"),
|
78 |
gr.Checkbox(label="Google Filter"),
|
@@ -80,8 +75,8 @@ iface = gr.Interface(
|
|
80 |
gr.Slider(1, 100, 10, label="Number of Results")
|
81 |
],
|
82 |
outputs="text",
|
83 |
-
title="SERPHouse Search Interface",
|
84 |
-
description="Enter your search
|
85 |
)
|
86 |
|
87 |
iface.launch()
|
|
|
3 |
|
4 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
5 |
|
6 |
+
# List of 50 major countries
|
7 |
MAJOR_COUNTRIES = [
|
8 |
"United States", "United Kingdom", "Canada", "Australia", "Germany",
|
9 |
"France", "Japan", "South Korea", "China", "India",
|
|
|
17 |
"Indonesia", "Philippines", "Vietnam", "Pakistan", "Bangladesh"
|
18 |
]
|
19 |
|
20 |
+
def search_serphouse(query, country, verbatim, gfilter, page, num_result):
|
21 |
url = "https://api.serphouse.com/serp/live"
|
22 |
|
23 |
params = {
|
24 |
"q": query,
|
25 |
+
"domain": "google.com",
|
26 |
+
"lang": "en",
|
27 |
+
"device": "desktop",
|
28 |
+
"serp_type": "news",
|
29 |
+
"loc": country,
|
30 |
"country": country,
|
31 |
"verbatim": verbatim,
|
32 |
"gfilter": gfilter,
|
|
|
47 |
|
48 |
def format_results(results):
|
49 |
if isinstance(results, dict) and "results" in results:
|
50 |
+
news_results = results["results"].get("news", [])
|
51 |
formatted_results = ""
|
52 |
+
for i, result in enumerate(news_results, 1):
|
53 |
formatted_results += f"{i}. {result['title']}\n"
|
54 |
formatted_results += f" URL: {result['link']}\n"
|
55 |
formatted_results += f" Snippet: {result['snippet']}\n\n"
|
|
|
57 |
else:
|
58 |
return str(results)
|
59 |
|
60 |
+
def serphouse_search(query, country, verbatim, gfilter, page, num_result):
|
61 |
verbatim = "1" if verbatim else "0"
|
62 |
gfilter = "1" if gfilter else "0"
|
63 |
|
64 |
+
results = search_serphouse(query, country, verbatim, gfilter, page, num_result)
|
65 |
return format_results(results)
|
66 |
|
67 |
iface = gr.Interface(
|
68 |
fn=serphouse_search,
|
69 |
inputs=[
|
70 |
gr.Textbox(label="Search Query"),
|
|
|
|
|
|
|
|
|
|
|
71 |
gr.Dropdown(MAJOR_COUNTRIES, label="Country"),
|
72 |
gr.Checkbox(label="Verbatim"),
|
73 |
gr.Checkbox(label="Google Filter"),
|
|
|
75 |
gr.Slider(1, 100, 10, label="Number of Results")
|
76 |
],
|
77 |
outputs="text",
|
78 |
+
title="SERPHouse News Search Interface",
|
79 |
+
description="Enter your search query and select a country to get news results from the SERPHouse API."
|
80 |
)
|
81 |
|
82 |
iface.launch()
|