Update app.py
Browse files
app.py
CHANGED
@@ -75,48 +75,58 @@ def create_deepseek_interface():
|
|
75 |
print(f"์๋ณธ ์ฟผ๋ฆฌ: {query}")
|
76 |
print(extraction_result)
|
77 |
|
78 |
-
# SerpHouse API ํธ์ถ ์คํ
|
79 |
-
|
80 |
-
|
|
|
|
|
81 |
"q": search_query,
|
82 |
"domain": "google.com",
|
83 |
-
"loc": "us",
|
84 |
"lang": "en",
|
85 |
"device": "desktop",
|
86 |
"serp_type": "web",
|
87 |
-
"
|
88 |
-
"
|
|
|
89 |
}
|
|
|
90 |
headers = {
|
91 |
-
"Content-Type": "application/json",
|
92 |
"Authorization": f"Bearer {serphouse_api_key}"
|
93 |
}
|
94 |
|
95 |
print(f"SerpHouse API ํธ์ถ ์ค... ๊ฒ์์ด: {search_query}")
|
96 |
-
|
|
|
|
|
|
|
97 |
response.raise_for_status()
|
98 |
|
99 |
-
print("SerpHouse API ์๋ต
|
100 |
search_results = response.json()
|
101 |
|
102 |
# ๊ฒ์ ๊ฒฐ๊ณผ ํ์ฑ ๋ฐ ํฌ๋งทํ
|
103 |
formatted_results = []
|
104 |
formatted_results.append(f"๊ฒ์์ด: {search_query}\n\n")
|
105 |
|
106 |
-
if "organic" in search_results and len(search_results["organic"]) > 0:
|
107 |
-
for result in search_results["organic"][:5]: # ์์ 5๊ฐ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
|
108 |
title = result.get("title", "์ ๋ชฉ ์์")
|
109 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
110 |
link = result.get("link", "#")
|
111 |
formatted_results.append(f"์ ๋ชฉ: {title}\n๋ด์ฉ: {snippet}\n๋งํฌ: {link}\n\n")
|
112 |
|
|
|
113 |
return "".join(formatted_results)
|
114 |
else:
|
115 |
-
|
|
|
|
|
116 |
|
117 |
except Exception as e:
|
118 |
error_msg = f"๊ฒ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
119 |
print(error_msg)
|
|
|
|
|
120 |
return error_msg
|
121 |
|
122 |
# ์คํธ๋ฆฌ๋ฐ ๋ฐฉ์์ผ๋ก DeepSeek API ํธ์ถ ํจ์
|
|
|
75 |
print(f"์๋ณธ ์ฟผ๋ฆฌ: {query}")
|
76 |
print(extraction_result)
|
77 |
|
78 |
+
# SerpHouse API ํธ์ถ ์คํ - GET ๋ฉ์๋ ์ฌ์ฉ
|
79 |
+
base_url = "https://api.serphouse.com/serp/live"
|
80 |
+
|
81 |
+
# ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ ์ค์
|
82 |
+
params = {
|
83 |
"q": search_query,
|
84 |
"domain": "google.com",
|
|
|
85 |
"lang": "en",
|
86 |
"device": "desktop",
|
87 |
"serp_type": "web",
|
88 |
+
"loc": "us", # ์์น ์ฝ๋
|
89 |
+
"page": "1",
|
90 |
+
"num": "5" # ์์ 5๊ฐ ๊ฒฐ๊ณผ๋ง ๊ฐ์ ธ์ค๊ธฐ
|
91 |
}
|
92 |
+
|
93 |
headers = {
|
|
|
94 |
"Authorization": f"Bearer {serphouse_api_key}"
|
95 |
}
|
96 |
|
97 |
print(f"SerpHouse API ํธ์ถ ์ค... ๊ฒ์์ด: {search_query}")
|
98 |
+
print(f"์์ฒญ URL: {base_url}?q={search_query}&domain=google.com&...")
|
99 |
+
|
100 |
+
# GET ์์ฒญ ์ํ
|
101 |
+
response = requests.get(base_url, headers=headers, params=params)
|
102 |
response.raise_for_status()
|
103 |
|
104 |
+
print(f"SerpHouse API ์๋ต ์ํ ์ฝ๋: {response.status_code}")
|
105 |
search_results = response.json()
|
106 |
|
107 |
# ๊ฒ์ ๊ฒฐ๊ณผ ํ์ฑ ๋ฐ ํฌ๋งทํ
|
108 |
formatted_results = []
|
109 |
formatted_results.append(f"๊ฒ์์ด: {search_query}\n\n")
|
110 |
|
111 |
+
if "results" in search_results and "organic" in search_results["results"] and len(search_results["results"]["organic"]) > 0:
|
112 |
+
for result in search_results["results"]["organic"][:5]: # ์์ 5๊ฐ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
|
113 |
title = result.get("title", "์ ๋ชฉ ์์")
|
114 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
115 |
link = result.get("link", "#")
|
116 |
formatted_results.append(f"์ ๋ชฉ: {title}\n๋ด์ฉ: {snippet}\n๋งํฌ: {link}\n\n")
|
117 |
|
118 |
+
print(f"๊ฒ์ ๊ฒฐ๊ณผ {len(search_results['results']['organic'])}๊ฐ ์ฐพ์")
|
119 |
return "".join(formatted_results)
|
120 |
else:
|
121 |
+
print("๊ฒ์ ๊ฒฐ๊ณผ ์์ ๋๋ ์๋ต ํ์ ๋ถ์ผ์น")
|
122 |
+
print(f"์๋ต ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: {str(search_results)[:300]}...")
|
123 |
+
return f"๊ฒ์์ด '{search_query}'์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์๊ฑฐ๋ API ์๋ต ํ์์ด ์์๊ณผ ๋ค๋ฆ
๋๋ค."
|
124 |
|
125 |
except Exception as e:
|
126 |
error_msg = f"๊ฒ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
127 |
print(error_msg)
|
128 |
+
import traceback
|
129 |
+
print(traceback.format_exc())
|
130 |
return error_msg
|
131 |
|
132 |
# ์คํธ๋ฆฌ๋ฐ ๋ฐฉ์์ผ๋ก DeepSeek API ํธ์ถ ํจ์
|