Spaces:
ginipick
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
5d3044b
·
verified ·
1 Parent(s): 34db24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
3
 
4
  API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
5
 
6
- # 주요 50 국가 목록 (영어 표기)
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, domain, language, device, serp_type, location, country, verbatim, gfilter, page, num_result):
21
  url = "https://api.serphouse.com/serp/live"
22
 
23
  params = {
24
  "q": query,
25
- "domain": domain,
26
- "lang": language,
27
- "device": device,
28
- "serp_type": serp_type,
29
- "loc": location,
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
- organic_results = results["results"].get("organic", [])
51
  formatted_results = ""
52
- for i, result in enumerate(organic_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,22 +57,17 @@ def format_results(results):
57
  else:
58
  return str(results)
59
 
60
- def serphouse_search(query, domain, language, device, serp_type, location, 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, domain, language, device, serp_type, location, 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(["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 parameters to get results from the SERPHouse API. You can now select from 50 major countries."
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()