Update app.py
Browse files
app.py
CHANGED
@@ -69,31 +69,34 @@ def create_deepseek_interface():
|
|
69 |
if not serphouse_api_key:
|
70 |
return "SERPHOUSE_API_KEYκ° μ€μ λμ§ μμμ΅λλ€."
|
71 |
|
72 |
-
# ν€μλ μΆμΆ
|
73 |
-
extraction_result, search_query = extract_keywords_with_llm(query)
|
74 |
-
print(f"μλ³Έ 쿼리: {query}")
|
75 |
-
print(extraction_result)
|
76 |
-
|
77 |
-
url = "https://api.serphouse.com/serp/live"
|
78 |
-
payload = {
|
79 |
-
"q": search_query,
|
80 |
-
"domain": "google.com",
|
81 |
-
"loc": "us",
|
82 |
-
"lang": "en",
|
83 |
-
"device": "desktop",
|
84 |
-
"serp_type": "web",
|
85 |
-
"page": 1,
|
86 |
-
"num": 5 # μμ 5κ° κ²°κ³Όλ§ κ°μ Έμ€κΈ°
|
87 |
-
}
|
88 |
-
headers = {
|
89 |
-
"Content-Type": "application/json",
|
90 |
-
"Authorization": f"Bearer {serphouse_api_key}"
|
91 |
-
}
|
92 |
-
|
93 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
response = requests.post(url, headers=headers, json=payload)
|
95 |
response.raise_for_status()
|
96 |
|
|
|
97 |
search_results = response.json()
|
98 |
|
99 |
# κ²μ κ²°κ³Ό νμ± λ° ν¬λ§·ν
|
@@ -112,7 +115,9 @@ def create_deepseek_interface():
|
|
112 |
return f"κ²μμ΄ '{search_query}'μ λν κ²μ κ²°κ³Όκ° μμ΅λλ€."
|
113 |
|
114 |
except Exception as e:
|
115 |
-
|
|
|
|
|
116 |
|
117 |
# μ€νΈλ¦¬λ° λ°©μμΌλ‘ DeepSeek API νΈμΆ ν¨μ
|
118 |
def query_deepseek_streaming(message, history, use_deep_research):
|
@@ -123,13 +128,17 @@ def create_deepseek_interface():
|
|
123 |
search_context = ""
|
124 |
search_info = ""
|
125 |
if use_deep_research:
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
133 |
λ€μμ μ¬μ©μ μ§λ¬Έκ³Ό κ΄λ ¨λ μ΅μ κ²μ κ²°κ³Όμ
λλ€. μ΄ μ 보λ₯Ό μ°Έκ³ νμ¬ μ ννκ³ μ΅μ μ λ³΄κ° λ°μλ μλ΅μ μ 곡νμΈμ:
|
134 |
|
135 |
{search_results}
|
@@ -137,7 +146,12 @@ def create_deepseek_interface():
|
|
137 |
μ κ²μ κ²°κ³Όλ₯Ό κΈ°λ°μΌλ‘ μ¬μ©μμ λ€μ μ§λ¬Έμ λ΅λ³νμΈμ. κ²μ κ²°κ³Όμμ λͺ
νν λ΅λ³μ μ°Ύμ μ μλ κ²½μ°, λΉμ μ μ§μμ νμ©νμ¬ μ΅μ μ λ΅λ³μ μ 곡νμΈμ.
|
138 |
κ²μ κ²°κ³Όλ₯Ό μΈμ©ν λλ μΆμ²λ₯Ό λͺ
μνκ³ , λ΅λ³μ΄ μ΅μ μ 보λ₯Ό λ°μνλλ‘ νμΈμ.
|
139 |
"""
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
# API μμ²μ μν λν κΈ°λ‘ μ€λΉ
|
143 |
messages = []
|
@@ -243,12 +257,24 @@ def create_deepseek_interface():
|
|
243 |
container=True
|
244 |
)
|
245 |
|
246 |
-
# Deep Research ν κΈ μΆκ°
|
247 |
with gr.Row():
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
# μ
λ ₯ μμ
|
254 |
with gr.Row():
|
|
|
69 |
if not serphouse_api_key:
|
70 |
return "SERPHOUSE_API_KEYκ° μ€μ λμ§ μμμ΅λλ€."
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
try:
|
73 |
+
# ν€μλ μΆμΆ
|
74 |
+
extraction_result, search_query = extract_keywords_with_llm(query)
|
75 |
+
print(f"μλ³Έ 쿼리: {query}")
|
76 |
+
print(extraction_result)
|
77 |
+
|
78 |
+
# SerpHouse API νΈμΆ μ€ν
|
79 |
+
url = "https://api.serphouse.com/serp/live"
|
80 |
+
payload = {
|
81 |
+
"q": search_query,
|
82 |
+
"domain": "google.com",
|
83 |
+
"loc": "us",
|
84 |
+
"lang": "en",
|
85 |
+
"device": "desktop",
|
86 |
+
"serp_type": "web",
|
87 |
+
"page": 1,
|
88 |
+
"num": 5 # μμ 5κ° κ²°κ³Όλ§ κ°μ Έμ€κΈ°
|
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 |
response = requests.post(url, headers=headers, json=payload)
|
97 |
response.raise_for_status()
|
98 |
|
99 |
+
print("SerpHouse API μλ΅ μμ μλ£")
|
100 |
search_results = response.json()
|
101 |
|
102 |
# κ²μ κ²°κ³Ό νμ± λ° ν¬λ§·ν
|
|
|
115 |
return f"κ²μμ΄ '{search_query}'μ λν κ²μ κ²°κ³Όκ° μμ΅λλ€."
|
116 |
|
117 |
except Exception as e:
|
118 |
+
error_msg = f"κ²μ μ€ μ€λ₯ λ°μ: {str(e)}"
|
119 |
+
print(error_msg)
|
120 |
+
return error_msg
|
121 |
|
122 |
# μ€νΈλ¦¬λ° λ°©μμΌλ‘ DeepSeek API νΈμΆ ν¨μ
|
123 |
def query_deepseek_streaming(message, history, use_deep_research):
|
|
|
128 |
search_context = ""
|
129 |
search_info = ""
|
130 |
if use_deep_research:
|
131 |
+
try:
|
132 |
+
# κ²μ μν (첫 λ©μμ§ μ λ¬)
|
133 |
+
yield history + [(message, "π μ΅μ μ ν€μλ μΆμΆ λ° μΉ κ²μ μ€...")], ""
|
134 |
+
|
135 |
+
# κ²μ μ€ν - λλ²κΉ
μ μν λ‘κ·Έ μΆκ°
|
136 |
+
print(f"Deep Research νμ±νλ¨: λ©μμ§ '{message}'μ λν κ²μ μμ")
|
137 |
+
search_results = search_with_serphouse(message)
|
138 |
+
print(f"κ²μ κ²°κ³Ό μμ μλ£: {search_results[:100]}...") # κ²°κ³Ό μλΆλΆλ§ μΆλ ₯
|
139 |
+
|
140 |
+
if not search_results.startswith("κ²μ μ€ μ€λ₯ λ°μ") and not search_results.startswith("SERPHOUSE_API_KEY"):
|
141 |
+
search_context = f"""
|
142 |
λ€μμ μ¬μ©μ μ§λ¬Έκ³Ό κ΄λ ¨λ μ΅μ κ²μ κ²°κ³Όμ
λλ€. μ΄ μ 보λ₯Ό μ°Έκ³ νμ¬ μ ννκ³ μ΅μ μ λ³΄κ° λ°μλ μλ΅μ μ 곡νμΈμ:
|
143 |
|
144 |
{search_results}
|
|
|
146 |
μ κ²μ κ²°κ³Όλ₯Ό κΈ°λ°μΌλ‘ μ¬μ©μμ λ€μ μ§λ¬Έμ λ΅λ³νμΈμ. κ²μ κ²°κ³Όμμ λͺ
νν λ΅λ³μ μ°Ύμ μ μλ κ²½μ°, λΉμ μ μ§μμ νμ©νμ¬ μ΅μ μ λ΅λ³μ μ 곡νμΈμ.
|
147 |
κ²μ κ²°κ³Όλ₯Ό μΈμ©ν λλ μΆμ²λ₯Ό λͺ
μνκ³ , λ΅λ³μ΄ μ΅μ μ 보λ₯Ό λ°μνλλ‘ νμΈμ.
|
148 |
"""
|
149 |
+
search_info = f"π Deep Research κΈ°λ₯ νμ±ν: κ΄λ ¨ μΉ κ²μ κ²°κ³Όλ₯Ό κΈ°λ°μΌλ‘ μλ΅ μμ± μ€..."
|
150 |
+
else:
|
151 |
+
print(f"κ²μ μ€ν¨ λλ κ²°κ³Ό μμ: {search_results}")
|
152 |
+
except Exception as e:
|
153 |
+
print(f"Deep Research μ²λ¦¬ μ€ μμΈ λ°μ: {str(e)}")
|
154 |
+
search_info = f"π Deep Research κΈ°λ₯ μ€λ₯: {str(e)}"
|
155 |
|
156 |
# API μμ²μ μν λν κΈ°λ‘ μ€λΉ
|
157 |
messages = []
|
|
|
257 |
container=True
|
258 |
)
|
259 |
|
260 |
+
# Deep Research ν κΈ λ° μν νμ μΆκ°
|
261 |
with gr.Row():
|
262 |
+
with gr.Column(scale=3):
|
263 |
+
use_deep_research = gr.Checkbox(
|
264 |
+
label="Deep Research νμ±ν",
|
265 |
+
info="μ΅μ μ ν€μλ μΆμΆ λ° μΉ κ²μμ ν΅ν μ΅μ μ 보 νμ©",
|
266 |
+
value=False
|
267 |
+
)
|
268 |
+
with gr.Column(scale=1):
|
269 |
+
api_status = gr.Markdown("API μν: μ€λΉλ¨")
|
270 |
+
|
271 |
+
# API ν€ μν νμΈ λ° νμ
|
272 |
+
if not serphouse_api_key:
|
273 |
+
api_status.value = "β οΈ SERPHOUSE_API_KEYκ° μ€μ λμ§ μμμ΅λλ€"
|
274 |
+
if not api_key:
|
275 |
+
api_status.value = "β οΈ FW_API_KEYκ° μ€μ λμ§ μμμ΅λλ€"
|
276 |
+
if api_key and serphouse_api_key:
|
277 |
+
api_status.value = "β
API ν€ μ€μ μλ£"
|
278 |
|
279 |
# μ
λ ₯ μμ
|
280 |
with gr.Row():
|