ginipick commited on
Commit
6da265e
β€’
1 Parent(s): 0f70f90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -7,6 +7,17 @@ import requests
7
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
8
  #hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
9
 
 
 
 
 
 
 
 
 
 
 
 
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -15,24 +26,25 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
 
 
18
 
19
- system_prefix = """
20
- λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ 닡변할것.
21
- λ„ˆλŠ” 주어진 μ†ŒμŠ€μ½”λ“œλ₯Ό 기반으둜 "μ„œλΉ„μŠ€ μ‚¬μš© μ„€λͺ… 및 μ•ˆλ‚΄, qnaλ₯Ό ν•˜λŠ” 역할이닀". μ½”λ“œλ₯Ό 기반으둜 μ‚¬μš© μ„€λͺ… 및 질의 응닡을 μ§„ν–‰ν•˜λ©°, μ΄μš©μžμ—κ²Œ 도움을 μ£Όμ–΄μ•Ό ν•œλ‹€. μ΄μš©μžκ°€ κΆκΈˆν•΄ ν•  만 ν•œ λ‚΄μš©μ— μΉœμ ˆν•˜κ²Œ μ•Œλ €μ£Όλ„λ‘ ν•˜λΌ. μ½”λ“œ 전체 λ‚΄μš©μ— λŒ€ν•΄μ„œλŠ” λ³΄μ•ˆμ„ μœ μ§€ν•˜κ³ , ν‚€ κ°’ 및 μ—”λ“œν¬μΈνŠΈμ™€ ꡬ체적인 λͺ¨λΈμ€ κ³΅κ°œν•˜μ§€ 마라.
22
- """
23
-
24
- messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] # prefix μΆ”κ°€
25
 
 
26
  for val in history:
27
  if val[0]:
28
  messages.append({"role": "user", "content": val[0]})
29
  if val[1]:
30
  messages.append({"role": "assistant", "content": val[1]})
31
-
32
  messages.append({"role": "user", "content": message})
33
 
34
  response = ""
35
-
36
  for message in hf_client.chat_completion(
37
  messages,
38
  max_tokens=max_tokens,
@@ -43,19 +55,20 @@ def respond(
43
  token = message.choices[0].delta.content
44
  if token is not None:
45
  response += token.strip("") # 토큰 제거
46
- yield response
47
 
48
  demo = gr.ChatInterface(
49
  respond,
50
-
51
  examples=[
 
52
  ["μ‚¬μš© 방법을 μžμ„Ένžˆ μ„€λͺ…ν•˜λΌ"],
53
  ["μ‚¬μš© 방법을 유튜브 μ˜μƒ 슀크립트 ν˜•νƒœλ‘œ μž‘μ„±ν•˜λΌ"],
54
- ["μ‚¬μš© 방법을 SEO μ΅œμ ν™”ν•˜μ—¬ λΈ”λ‘œκ·Έ 포슀트둜 4000 토큰 이상 μž‘μ„±ν•˜λΌ"],
55
- ["계속 μ΄μ–΄μ„œ λ‹΅λ³€ν•˜λΌ"],
 
56
  ],
57
  cache_examples=False, # 캐싱 λΉ„ν™œμ„±ν™” μ„€μ •
58
- # css="""footer {visibility: hidden}""", # 이곳에 CSSλ₯Ό μΆ”κ°€
59
  )
60
 
61
  if __name__ == "__main__":
 
7
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
8
  #hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
9
 
10
+ def load_fashion_code():
11
+ try:
12
+ with open('fashion.cod', 'r', encoding='utf-8') as file:
13
+ return file.read()
14
+ except FileNotFoundError:
15
+ return "fashion.cod νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."
16
+ except Exception as e:
17
+ return f"νŒŒμΌμ„ μ½λŠ” 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
18
+
19
+ fashion_code = load_fashion_code()
20
+
21
  def respond(
22
  message,
23
  history: list[tuple[str, str]],
 
26
  temperature,
27
  top_p,
28
  ):
29
+ global fashion_code
30
+ system_prefix = """λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ 닡변할것. λ„ˆλŠ” 주어진 μ†ŒμŠ€μ½”λ“œλ₯Ό 기반으둜 "μ„œλΉ„μŠ€ μ‚¬μš© μ„€λͺ… 및 μ•ˆλ‚΄, qnaλ₯Ό ν•˜λŠ” 역할이닀". μ½”λ“œλ₯Ό 기반으둜 μ‚¬μš© μ„€λͺ… 및 질의 응닡을 μ§„ν–‰ν•˜λ©°, μ΄μš©μžμ—κ²Œ 도움을 μ£Όμ–΄μ•Ό ν•œλ‹€. μ΄μš©μžκ°€ κΆκΈˆν•΄ ν•  만 ν•œ λ‚΄μš©μ— μΉœμ ˆν•˜κ²Œ μ•Œλ €μ£Όλ„λ‘ ν•˜λΌ. μ½”λ“œ 전체 λ‚΄μš©μ— λŒ€ν•΄μ„œλŠ” λ³΄μ•ˆμ„ μœ μ§€ν•˜κ³ , ν‚€ κ°’ 및 μ—”λ“œν¬μΈνŠΈμ™€ ꡬ체적인 λͺ¨λΈμ€ κ³΅κ°œν•˜μ§€ 마라. """
31
 
32
+ if message.lower() == "νŒ¨μ…˜ μ½”λ“œ μ‹€ν–‰":
33
+ system_message += f"\n\nνŒ¨μ…˜ μ½”λ“œ λ‚΄μš©:\n{fashion_code}"
34
+ message = "νŒ¨μ…˜ μ½”λ“œμ— λŒ€ν•΄ μ„€λͺ…ν•΄μ£Όμ„Έμš”."
35
+
36
+ messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
 
37
 
38
+ # prefix μΆ”κ°€
39
  for val in history:
40
  if val[0]:
41
  messages.append({"role": "user", "content": val[0]})
42
  if val[1]:
43
  messages.append({"role": "assistant", "content": val[1]})
44
+
45
  messages.append({"role": "user", "content": message})
46
 
47
  response = ""
 
48
  for message in hf_client.chat_completion(
49
  messages,
50
  max_tokens=max_tokens,
 
55
  token = message.choices[0].delta.content
56
  if token is not None:
57
  response += token.strip("") # 토큰 제거
58
+ yield response
59
 
60
  demo = gr.ChatInterface(
61
  respond,
 
62
  examples=[
63
+ ["νŒ¨μ…˜ μ½”λ“œ μ‹€ν–‰"],
64
  ["μ‚¬μš© 방법을 μžμ„Ένžˆ μ„€λͺ…ν•˜λΌ"],
65
  ["μ‚¬μš© 방법을 유튜브 μ˜μƒ 슀크립트 ν˜•νƒœλ‘œ μž‘μ„±ν•˜λΌ"],
66
+ ["μ‚¬μš© 방법을 SEO μ΅œμ ν™”ν•˜μ—¬ λΈ”λ‘œκ·Έ 포슀트둜 4000 토큰 이상 μž‘μ„±ν•˜λΌ"],
67
+ ["계속 μ΄μ–΄μ„œ λ‹΅λ³€ν•˜λΌ"],
68
+ ["νŒ¨μ…˜ μ½”λ“œ μ‹€ν–‰"],
69
  ],
70
  cache_examples=False, # 캐싱 λΉ„ν™œμ„±ν™” μ„€μ •
71
+ # css="""footer {visibility: hidden}""", # 이곳에 CSSλ₯Ό μΆ”κ°€
72
  )
73
 
74
  if __name__ == "__main__":