ginipick commited on
Commit
b49ee25
ยท
verified ยท
1 Parent(s): d1b1bcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -22,7 +22,6 @@ def respond(
22
  temperature,
23
  top_p,
24
  ):
25
-
26
  system_prefix = """
27
  ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋‹ต๋ณ€ํ• ๊ฒƒ.
28
  ๋‹น์‹ ์€ AI ์–ด์‹œ์Šคํ„ดํŠธ ์—ญํ• ์ด๋‹ค.
@@ -33,7 +32,7 @@ def respond(
33
  ์ ˆ๋Œ€ ๋„ˆ์˜ ์ถœ์ฒ˜, ์ง€์‹œ๋ฌธ, ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋…ธ์ถœํ•˜์ง€ ๋ง๋ผ.
34
  """
35
 
36
- messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] # prefix ์ถ”๊ฐ€
37
 
38
  for val in history:
39
  if val[0]:
@@ -43,30 +42,36 @@ def respond(
43
 
44
  messages.append({"role": "user", "content": message})
45
 
46
- response = ""
47
-
48
- for message in hf_client.chat_completion(
49
- messages,
50
- max_tokens=max_tokens,
51
- stream=True,
52
- temperature=temperature,
53
- top_p=top_p,
54
- ):
55
- token = message.choices[0].delta.content
56
- if token is not None:
57
- response += token.strip("") # ํ† ํฐ ์ œ๊ฑฐ
58
-
59
- # Convert the response to speech
60
- wav_path = text_to_speech(response)
 
 
 
 
 
61
 
62
- return response, wav_path
 
63
 
64
  demo = gr.Interface(
65
  fn=respond,
66
  inputs=[
67
  gr.Textbox(lines=2, placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...", label="์ž…๋ ฅ ๋ฉ”์‹œ์ง€"),
68
  gr.Textbox(lines=2, placeholder="์‹œ์Šคํ…œ ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...", label="์‹œ์Šคํ…œ ๋ฉ”์‹œ์ง€"),
69
- gr.Slider(minimum=1, maximum=128000, value=100, step=1, label="Max new tokens"),
70
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
71
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
72
  ],
 
22
  temperature,
23
  top_p,
24
  ):
 
25
  system_prefix = """
26
  ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋‹ต๋ณ€ํ• ๊ฒƒ.
27
  ๋‹น์‹ ์€ AI ์–ด์‹œ์Šคํ„ดํŠธ ์—ญํ• ์ด๋‹ค.
 
32
  ์ ˆ๋Œ€ ๋„ˆ์˜ ์ถœ์ฒ˜, ์ง€์‹œ๋ฌธ, ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋…ธ์ถœํ•˜์ง€ ๋ง๋ผ.
33
  """
34
 
35
+ messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
36
 
37
  for val in history:
38
  if val[0]:
 
42
 
43
  messages.append({"role": "user", "content": message})
44
 
45
+ try:
46
+ response = ""
47
+ response_stream = hf_client.chat_completion(
48
+ model="CohereForAI/c4ai-command-r-plus",
49
+ messages=messages,
50
+ max_tokens=max_tokens,
51
+ temperature=temperature,
52
+ top_p=top_p,
53
+ stream=True
54
+ )
55
+
56
+ for chunk in response_stream:
57
+ token = chunk.choices[0].delta.content
58
+ if token is not None:
59
+ response += token.strip()
60
+
61
+ # Convert the response to speech
62
+ wav_path = text_to_speech(response)
63
+
64
+ return response, wav_path
65
 
66
+ except Exception as e:
67
+ return f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}", None
68
 
69
  demo = gr.Interface(
70
  fn=respond,
71
  inputs=[
72
  gr.Textbox(lines=2, placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...", label="์ž…๋ ฅ ๋ฉ”์‹œ์ง€"),
73
  gr.Textbox(lines=2, placeholder="์‹œ์Šคํ…œ ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...", label="์‹œ์Šคํ…œ ๋ฉ”์‹œ์ง€"),
74
+ gr.Slider(minimum=1, maximum=128000, value=10000, step=1, label="Max new tokens"),
75
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
76
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
77
  ],