SUHHHH commited on
Commit
ebe28f0
·
verified ·
1 Parent(s): 4f263cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -3,31 +3,31 @@ from huggingface_hub import InferenceClient
3
  import os
4
  from typing import Optional
5
 
6
- # DeepSeek-V3 모델 ID
7
- DEEPSEEK_MODEL = "deepseek-chat"
8
 
9
- def get_client():
10
  """
11
  HuggingFace InferenceClient 생성.
12
  hf_token을 secrets에서 가져옴.
13
  """
14
- hf_token = os.environ.get("HF_TOKEN")
15
  if not hf_token:
16
  raise ValueError("HuggingFace API 토큰이 필요합니다.")
17
- return InferenceClient(DEEPSEEK_MODEL, token=hf_token)
18
 
19
- def respond_deepseek_qna(
20
  question: str,
21
  system_message: str,
22
  max_tokens: int,
23
  temperature: float,
24
- top_p: float
 
25
  ):
26
  """
27
- DeepSeek-V3 모델을 이용해 한 번의 질문(question)에 대한 답변을 반환하는 함수.
28
  """
29
  try:
30
- client = get_client()
31
  except ValueError as e:
32
  return f"오류: {str(e)}"
33
 
@@ -73,36 +73,36 @@ with gr.Blocks() as demo:
73
  answer_output = gr.Textbox(label="결과", lines=10, interactive=False)
74
 
75
  # 고급 설정 (코드 내부에서만 사용)
76
- with gr.Accordion("고급 설정 (DeepSeek-V3)", open=False):
77
- system_message = gr.Textbox(
78
- value="""반드시 한글로 답변할 것.
79
  너는 최고의 블로그 글 생성기이다.
80
  주어진 참조글을 바탕으로 블로그 글을 생성하라.
81
  말투는 선택된 옵션에 맞게 조정하라.
82
  """,
83
- label="System Message",
84
- lines=3
85
- )
86
- max_tokens = gr.Slider(minimum=100, maximum=2000, value=500, step=100, label="Max Tokens")
87
- temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
88
- top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
89
 
90
  # 전송 버튼
91
  submit_button = gr.Button("생성")
92
 
93
- def merge_and_call_deepseek(tone, ref1, ref2, ref3, sys_msg, mt, temp, top_p_):
94
  # 참조글을 합쳐서 질문 구성
95
  question = f"말투: {tone}\n참조글 1: {ref1}\n참조글 2: {ref2}\n참조글 3: {ref3}"
96
- return respond_deepseek_qna(
 
97
  question=question,
98
  system_message=sys_msg,
99
  max_tokens=mt,
100
  temperature=temp,
101
- top_p=top_p_
 
102
  )
103
 
104
  submit_button.click(
105
- fn=merge_and_call_deepseek,
106
  inputs=[
107
  tone_radio, ref1, ref2, ref3,
108
  system_message,
 
3
  import os
4
  from typing import Optional
5
 
6
+ # Cohere Command R+ 모델 ID
7
+ COHERE_MODEL = "CohereForAI/c4ai-command-r-plus-08-2024"
8
 
9
+ def get_client(hf_token):
10
  """
11
  HuggingFace InferenceClient 생성.
12
  hf_token을 secrets에서 가져옴.
13
  """
 
14
  if not hf_token:
15
  raise ValueError("HuggingFace API 토큰이 필요합니다.")
16
+ return InferenceClient(COHERE_MODEL, token=hf_token)
17
 
18
+ def respond_cohere_qna(
19
  question: str,
20
  system_message: str,
21
  max_tokens: int,
22
  temperature: float,
23
+ top_p: float,
24
+ hf_token: str
25
  ):
26
  """
27
+ Cohere Command R+ 모델을 이용해 한 번의 질문(question)에 대한 답변을 반환하는 함수.
28
  """
29
  try:
30
+ client = get_client(hf_token)
31
  except ValueError as e:
32
  return f"오류: {str(e)}"
33
 
 
73
  answer_output = gr.Textbox(label="결과", lines=10, interactive=False)
74
 
75
  # 고급 설정 (코드 내부에서만 사용)
76
+ system_message = gr.Textbox(
77
+ value="""반드시 한글로 답변할 것.
 
78
  너는 최고의 블로그 글 생성기이다.
79
  주어진 참조글을 바탕으로 블로그 글을 생성하라.
80
  말투는 선택된 옵션에 맞게 조정하라.
81
  """,
82
+ visible=False # UI에서 숨김
83
+ )
84
+ max_tokens = gr.Slider(minimum=100, maximum=10000, value=4000, step=100, label="Max Tokens", visible=False)
85
+ temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature", visible=False)
86
+ top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P", visible=False)
 
87
 
88
  # 전송 버튼
89
  submit_button = gr.Button("생성")
90
 
91
+ def merge_and_call_cohere(tone, ref1, ref2, ref3, sys_msg, mt, temp, top_p_):
92
  # 참조글을 합쳐서 질문 구성
93
  question = f"말투: {tone}\n참조글 1: {ref1}\n참조글 2: {ref2}\n참조글 3: {ref3}"
94
+ hf_token = os.environ.get("HF_TOKEN")
95
+ return respond_cohere_qna(
96
  question=question,
97
  system_message=sys_msg,
98
  max_tokens=mt,
99
  temperature=temp,
100
+ top_p=top_p_,
101
+ hf_token=hf_token
102
  )
103
 
104
  submit_button.click(
105
+ fn=merge_and_call_cohere,
106
  inputs=[
107
  tone_radio, ref1, ref2, ref3,
108
  system_message,