Update app.py
Browse files
app.py
CHANGED
@@ -75,73 +75,79 @@ def create_deepseek_interface():
|
|
75 |
print(f"์๋ณธ ์ฟผ๋ฆฌ: {query}")
|
76 |
print(extraction_result)
|
77 |
|
78 |
-
# ํ๊ธ
|
79 |
-
# ํ๊ธ ์ฌ์ฉ ์ ํ๊ตญ(kr) ๋ก์ผ์ผ๋ก ๋ณ๊ฒฝ
|
80 |
is_korean = any('\uAC00' <= c <= '\uD7A3' for c in search_query)
|
81 |
-
|
|
|
82 |
|
83 |
-
# SerpHouse API ํธ์ถ ์คํ -
|
84 |
-
|
85 |
|
86 |
-
#
|
87 |
-
|
88 |
-
"
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
96 |
}
|
97 |
|
98 |
headers = {
|
99 |
-
"
|
|
|
|
|
100 |
}
|
101 |
|
102 |
-
print(f"SerpHouse API ํธ์ถ ์ค... ๊ฒ์์ด: {
|
103 |
-
print(f"์์ฒญ
|
104 |
|
105 |
-
#
|
106 |
-
response = requests.
|
107 |
response.raise_for_status()
|
108 |
|
109 |
print(f"SerpHouse API ์๋ต ์ํ ์ฝ๋: {response.status_code}")
|
110 |
search_results = response.json()
|
111 |
|
112 |
-
# ์๋ต ๊ตฌ์กฐ
|
113 |
-
print(f"์๋ต ๊ตฌ์กฐ: {list(search_results.keys())}")
|
114 |
-
if "results" in search_results:
|
115 |
-
print(f"results ๊ตฌ์กฐ: {list(search_results['results'].keys()) if isinstance(search_results['results'], dict) else '๋ฆฌ์คํธ'}")
|
116 |
|
117 |
# ๊ฒ์ ๊ฒฐ๊ณผ ํ์ฑ ๋ฐ ํฌ๋งทํ
|
118 |
formatted_results = []
|
119 |
-
formatted_results.append(f"๊ฒ์์ด: {
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
134 |
title = result.get("title", "์ ๋ชฉ ์์")
|
135 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
136 |
link = result.get("link", "#")
|
137 |
formatted_results.append(f"์ ๋ชฉ: {title}\n๋ด์ฉ: {snippet}\n๋งํฌ: {link}\n\n")
|
138 |
|
139 |
-
print(f"๊ฒ์ ๊ฒฐ๊ณผ {len(
|
140 |
return "".join(formatted_results)
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
|
146 |
except Exception as e:
|
147 |
error_msg = f"๊ฒ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
|
75 |
print(f"์๋ณธ ์ฟผ๋ฆฌ: {query}")
|
76 |
print(extraction_result)
|
77 |
|
78 |
+
# ํ๊ธ ๊ฒ์์ด์ธ์ง ํ์ธํ๊ณ ์ ์ ํ ์ค์ ์ ํ
|
|
|
79 |
is_korean = any('\uAC00' <= c <= '\uD7A3' for c in search_query)
|
80 |
+
lang = "ko" if is_korean else "en"
|
81 |
+
loc = "kr" if is_korean else "us"
|
82 |
|
83 |
+
# SerpHouse API ํธ์ถ ์คํ - POST ๋ฉ์๋ ์ฌ์ฉ (MoneyRadar ์ฝ๋ ์ฐธ๊ณ )
|
84 |
+
url = "https://api.serphouse.com/serp/live"
|
85 |
|
86 |
+
# MoneyRadar ๋ฐฉ์์ผ๋ก ํ์ด๋ก๋ ๊ตฌ์ฑ
|
87 |
+
payload = {
|
88 |
+
"data": {
|
89 |
+
"q": search_query.replace(',', ' ').strip(),
|
90 |
+
"domain": "google.com",
|
91 |
+
"loc": loc,
|
92 |
+
"lang": lang,
|
93 |
+
"device": "desktop",
|
94 |
+
"serp_type": "web",
|
95 |
+
"page": "1",
|
96 |
+
"num": "5"
|
97 |
+
}
|
98 |
}
|
99 |
|
100 |
headers = {
|
101 |
+
"accept": "application/json",
|
102 |
+
"content-type": "application/json",
|
103 |
+
"authorization": f"Bearer {serphouse_api_key}"
|
104 |
}
|
105 |
|
106 |
+
print(f"SerpHouse API ํธ์ถ ์ค... ๊ฒ์์ด: {search_query}")
|
107 |
+
print(f"์์ฒญ ๋ฐฉ์: POST, ํ์ด๋ก๋: {payload}")
|
108 |
|
109 |
+
# POST ์์ฒญ ์ํ
|
110 |
+
response = requests.post(url, json=payload, headers=headers, timeout=(30, 30))
|
111 |
response.raise_for_status()
|
112 |
|
113 |
print(f"SerpHouse API ์๋ต ์ํ ์ฝ๋: {response.status_code}")
|
114 |
search_results = response.json()
|
115 |
|
116 |
+
# ์๋ต ๊ตฌ์กฐ ๋ก๊น
|
117 |
+
print(f"์๋ต ๊ตฌ์กฐ: {list(search_results.keys()) if isinstance(search_results, dict) else '๋์
๋๋ฆฌ ์๋'}")
|
|
|
|
|
118 |
|
119 |
# ๊ฒ์ ๊ฒฐ๊ณผ ํ์ฑ ๋ฐ ํฌ๋งทํ
|
120 |
formatted_results = []
|
121 |
+
formatted_results.append(f"๊ฒ์์ด: {search_query}\n\n")
|
122 |
|
123 |
+
if "results" in search_results:
|
124 |
+
results = search_results["results"]
|
125 |
+
if "organic" in results:
|
126 |
+
organic_results = results["organic"]
|
127 |
+
for result in organic_results[:5]: # ์์ 5๊ฐ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ
|
128 |
+
title = result.get("title", "์ ๋ชฉ ์์")
|
129 |
+
snippet = result.get("snippet", "๋ด์ฉ ๏ฟฝ๏ฟฝ๏ฟฝ์")
|
130 |
+
link = result.get("link", "#")
|
131 |
+
formatted_results.append(f"์ ๋ชฉ: {title}\n๋ด์ฉ: {snippet}\n๋งํฌ: {link}\n\n")
|
132 |
+
|
133 |
+
print(f"๊ฒ์ ๊ฒฐ๊ณผ {len(organic_results)}๊ฐ ์ฐพ์")
|
134 |
+
return "".join(formatted_results)
|
135 |
+
|
136 |
+
# ๋ค๋ฅธ ๊ฐ๋ฅํ ๊ฒฐ๊ณผ ๊ตฌ์กฐ ํ์ธ
|
137 |
+
if isinstance(search_results, dict) and "organic" in search_results:
|
138 |
+
organic_results = search_results["organic"]
|
139 |
+
for result in organic_results[:5]:
|
140 |
title = result.get("title", "์ ๋ชฉ ์์")
|
141 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
142 |
link = result.get("link", "#")
|
143 |
formatted_results.append(f"์ ๋ชฉ: {title}\n๋ด์ฉ: {snippet}\n๋งํฌ: {link}\n\n")
|
144 |
|
145 |
+
print(f"๊ฒ์ ๊ฒฐ๊ณผ {len(organic_results)}๊ฐ ์ฐพ์")
|
146 |
return "".join(formatted_results)
|
147 |
+
|
148 |
+
print("๊ฒ์ ๊ฒฐ๊ณผ ์์ ๋๋ ์๋ต ํ์ ๋ถ์ผ์น")
|
149 |
+
print(f"์๋ต ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: {str(search_results)[:300]}...")
|
150 |
+
return f"๊ฒ์์ด '{search_query}'์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์๊ฑฐ๋ API ์๋ต ํ์์ด ์์๊ณผ ๋ค๋ฆ
๋๋ค."
|
151 |
|
152 |
except Exception as e:
|
153 |
error_msg = f"๊ฒ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|