m97j commited on
Commit
17ee8b7
Β·
1 Parent(s): b635cd2

Initial commit

Browse files
.gitignore CHANGED
@@ -15,7 +15,6 @@ venv/
15
 
16
  # models/ ν•˜μœ„ 디렉토리 포함, λͺ¨λΈ νŒŒμΌλ“€μ€ λ¬΄μ‹œ
17
  models/emotion-classification-model/*
18
- !models/emotion-classification-model/.gitkeep
19
 
20
  models/fallback-npc-model/*
21
  !models/fallback-npc-model/.gitkeep
 
15
 
16
  # models/ ν•˜μœ„ 디렉토리 포함, λͺ¨λΈ νŒŒμΌλ“€μ€ λ¬΄μ‹œ
17
  models/emotion-classification-model/*
 
18
 
19
  models/fallback-npc-model/*
20
  !models/fallback-npc-model/.gitkeep
models/emotion-classification-model/.gitkeep DELETED
File without changes
models/emotion_model.py DELETED
@@ -1,17 +0,0 @@
1
- from transformers import pipeline
2
- from fastapi import Request
3
-
4
- async def detect_emotion(request: Request, text: str) -> dict:
5
- tokenizer = request.app.state.emotion_tokenizer
6
- model = request.app.state.emotion_model
7
-
8
- emotion_pipeline = pipeline(
9
- "text-classification",
10
- model=model,
11
- tokenizer=tokenizer,
12
- return_all_scores=True
13
- )
14
-
15
- results = emotion_pipeline(text)
16
- # κ²°κ³Όλ₯Ό label: score ν˜•νƒœλ‘œ λ³€ν™˜
17
- return {r["label"]: r["score"] for r in results[0]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pipeline/preprocess.py CHANGED
@@ -34,6 +34,19 @@ def _semantic_match_embedder(embedder, user_input: str, trigger_texts: list, thr
34
  matched_text = trigger_texts[int(idx.item())]
35
  return (score_val >= threshold, score_val, matched_text)
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  async def _llm_trigger_check(request: Request, user_input: str, label_list: list) -> bool:
38
  if not label_list:
39
  return False
@@ -72,7 +85,7 @@ async def preprocess_input(
72
  context: dict
73
  ) -> dict:
74
  parser = ContextParser(context)
75
- emotion = await detect_emotion(request, user_input) # async 처리
76
 
77
  require_items = context.get("require", {}).get("items", [])
78
  require_actions = context.get("require", {}).get("actions", [])
 
34
  matched_text = trigger_texts[int(idx.item())]
35
  return (score_val >= threshold, score_val, matched_text)
36
 
37
+ async def extract_emotion_via_fallback(request: Request, user_input: str) -> str:
38
+ prompt = (
39
+ "λ‹€μŒ λ¬Έμž₯의 ν™”μž 감정을 ν•œ 단어 λ˜λŠ” 짧은 λ¬Έμž₯으둜 μ„€λͺ…ν•˜μ‹œμ˜€.\n\n"
40
+ f"[λ¬Έμž₯]\n{user_input}\n\n"
41
+ "μ§€μ‹œ:\n- 감정을 μ§μ ‘μ μœΌλ‘œ ν‘œν˜„ν•˜μ§€ μ•Šμ•„λ„ λ¬Έλ§₯을 톡해 μΆ”λ‘ ν•˜μ‹œμ˜€.\n"
42
+ "- κ°€λŠ₯ν•œ 경우 κ°μ •μ˜ κ°•λ„λ‚˜ λ‰˜μ•™μŠ€λ„ λ°˜μ˜ν•˜μ‹œμ˜€.\n"
43
+ "- 예: λΆ„λ…Έ, μŠ¬ν””, ν˜Όλž€, κΈ°λŒ€, 무관심, μ΄ˆμ‘°ν•¨ λ“±\n"
44
+ "- 단어 ν•˜λ‚˜ λ˜λŠ” 짧은 λ¬Έμž₯으둜만 좜λ ₯ν•˜μ‹œμ˜€.\n\n"
45
+ "μ •λ‹΅:"
46
+ )
47
+ response = await generate_fallback_response(request, prompt)
48
+ return response.strip()
49
+
50
  async def _llm_trigger_check(request: Request, user_input: str, label_list: list) -> bool:
51
  if not label_list:
52
  return False
 
85
  context: dict
86
  ) -> dict:
87
  parser = ContextParser(context)
88
+ emotion = await extract_emotion_via_fallback(request, user_input)
89
 
90
  require_items = context.get("require", {}).get("items", [])
91
  require_actions = context.get("require", {}).get("actions", [])