Spaces:
Sleeping
Sleeping
Update api.py
Browse files
api.py
CHANGED
@@ -372,26 +372,13 @@ def simple_intent_classifier(text):
|
|
372 |
text = text.lower()
|
373 |
greet_keywords = ["μλ
", "λ°κ°μ", "μ΄λ¦", "λꡬ", "μκ°", "μ΄λμ μ", "μ 체", "λͺ μ΄", "λ λμΌ"]
|
374 |
info_keywords = ["μ€λͺ
", "μ 보", "무μ", "λμΌ", "μ΄λ", "λꡬ", "μ", "μ΄λ»κ²", "μ’
λ₯", "κ°λ
"]
|
375 |
-
math_keywords = ["λνκΈ°", "λΉΌκΈ°", "κ³±νκΈ°", "λλκΈ°", "루νΈ", "μ κ³±", "+", "-", "*", "/", "=", "^", "β", "κ³μ°", "λͺμ΄μΌ", "μΌλ§μΌ"]
|
376 |
if any(kw in text for kw in greet_keywords):
|
377 |
return "μΈμ¬"
|
378 |
elif any(kw in text for kw in info_keywords):
|
379 |
return "μ 보μ§λ¬Έ"
|
380 |
-
elif any(kw in text for kw in math_keywords):
|
381 |
-
return "μνμ§λ¬Έ"
|
382 |
else:
|
383 |
return "μΌμλν"
|
384 |
|
385 |
-
def parse_math_question(text):
|
386 |
-
text = text.replace("κ³±νκΈ°", "*").replace("λνκΈ°", "+").replace("λΉΌκΈ°", "-").replace("λλκΈ°", "/").replace("μ κ³±", "*2")
|
387 |
-
text = re.sub(r'루νΈ\s(\d+)', r'math.sqrt(\1)', text)
|
388 |
-
try:
|
389 |
-
result = eval(text)
|
390 |
-
return f"μ λ΅μ {result}μ
λλ€."
|
391 |
-
except:
|
392 |
-
return "κ³μ°ν μ μλ μμμ΄μμ. λ€μ νλ² νμΈν΄ μ£ΌμΈμ!"
|
393 |
-
|
394 |
-
|
395 |
def respond(input_text):
|
396 |
# 1) μ¬μ©μ μ
λ ₯ κΈ°μ΅μ μ μ₯ (μνλ©΄)
|
397 |
memory.add(input_text)
|
@@ -408,11 +395,6 @@ def respond(input_text):
|
|
408 |
memory.add(response)
|
409 |
return response
|
410 |
|
411 |
-
if intent == "μνμ§λ¬Έ":
|
412 |
-
response = parse_math_question(input_text)
|
413 |
-
memory.add(response)
|
414 |
-
return response
|
415 |
-
|
416 |
if intent == "μ 보μ§λ¬Έ":
|
417 |
keyword = re.sub(r"(μ λν΄|μ λν|μ λν΄μ)?\s*(μ€λͺ
ν΄μ€|μλ €μ€|λμΌ|κ°λ
|μ μ|μ 보)?", "", input_text).strip()
|
418 |
if not keyword:
|
|
|
372 |
text = text.lower()
|
373 |
greet_keywords = ["μλ
", "λ°κ°μ", "μ΄λ¦", "λꡬ", "μκ°", "μ΄λμ μ", "μ 체", "λͺ μ΄", "λ λμΌ"]
|
374 |
info_keywords = ["μ€λͺ
", "μ 보", "무μ", "λμΌ", "μ΄λ", "λꡬ", "μ", "μ΄λ»κ²", "μ’
λ₯", "κ°λ
"]
|
|
|
375 |
if any(kw in text for kw in greet_keywords):
|
376 |
return "μΈμ¬"
|
377 |
elif any(kw in text for kw in info_keywords):
|
378 |
return "μ 보μ§λ¬Έ"
|
|
|
|
|
379 |
else:
|
380 |
return "μΌμλν"
|
381 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
def respond(input_text):
|
383 |
# 1) μ¬μ©μ μ
λ ₯ κΈ°μ΅μ μ μ₯ (μνλ©΄)
|
384 |
memory.add(input_text)
|
|
|
395 |
memory.add(response)
|
396 |
return response
|
397 |
|
|
|
|
|
|
|
|
|
|
|
398 |
if intent == "μ 보μ§λ¬Έ":
|
399 |
keyword = re.sub(r"(μ λν΄|μ λν|μ λν΄μ)?\s*(μ€λͺ
ν΄μ€|μλ €μ€|λμΌ|κ°λ
|μ μ|μ 보)?", "", input_text).strip()
|
400 |
if not keyword:
|