Kims12 commited on
Commit
90b6ab4
·
verified ·
1 Parent(s): 2fa1592

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -117
app.py CHANGED
@@ -9,16 +9,6 @@ from typing import Optional
9
  # [기본코드] - 수정/삭제 불가
10
  #############################
11
 
12
- # 제거할 모델들을 MODELS 사전에서 제외
13
- MODELS = {
14
- "Zephyr 7B Beta": "HuggingFaceH4/zephyr-7b-beta",
15
- "Meta Llama 3.1 8B": "meta-llama/Meta-Llama-3.1-8B-Instruct",
16
- "Meta-Llama 3.1 70B-Instruct": "meta-llama/Meta-Llama-3.1-70B-Instruct",
17
- "Microsoft": "microsoft/Phi-3-mini-4k-instruct",
18
- "Mixtral 8x7B": "mistralai/Mistral-7B-Instruct-v0.3",
19
- "Mixtral Nous-Hermes": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
20
- "Aya-23-35B": "CohereForAI/aya-23-35B"}
21
-
22
  # Cohere Command R+ 모델 ID 정의
23
  COHERE_MODEL = "CohereForAI/c4ai-command-r-plus-08-2024"
24
 
@@ -31,51 +21,12 @@ def get_client(model_name):
31
  if not hf_token:
32
  raise ValueError("HuggingFace API 토큰이 필요합니다.")
33
 
34
- if model_name in MODELS:
35
- model_id = MODELS[model_name]
36
- elif model_name == "Cohere Command R+":
37
  model_id = COHERE_MODEL
38
  else:
39
  raise ValueError("유효하지 않은 모델 이름입니다.")
40
  return InferenceClient(model_id, token=hf_token)
41
 
42
-
43
- def respond_hf_qna(
44
- question: str,
45
- model_name: str,
46
- max_tokens: int,
47
- temperature: float,
48
- top_p: float,
49
- system_message: str
50
- ):
51
- """
52
- HuggingFace 모델(Zephyr 등)에 대해 한 번의 질문(question)에 대한 답변을 반환하는 함수.
53
- """
54
- try:
55
- client = get_client(model_name)
56
- except ValueError as e:
57
- return f"오류: {str(e)}"
58
-
59
- messages = [
60
- {"role": "system", "content": system_message},
61
- {"role": "user", "content": question}
62
- ]
63
-
64
- try:
65
- response = client.chat_completion(
66
- messages,
67
- max_tokens=max_tokens,
68
- temperature=temperature,
69
- top_p=top_p,
70
- stream=False,
71
- )
72
- assistant_message = response.choices[0].message.content
73
- return assistant_message
74
-
75
- except Exception as e:
76
- return f"오류가 발생했습니다: {str(e)}"
77
-
78
-
79
  def respond_cohere_qna(
80
  question: str,
81
  system_message: str,
@@ -109,7 +60,6 @@ def respond_cohere_qna(
109
  except Exception as e:
110
  return f"오류가 발생했습니다: {str(e)}"
111
 
112
-
113
  def respond_chatgpt_qna(
114
  question: str,
115
  system_message: str,
@@ -144,7 +94,6 @@ def respond_chatgpt_qna(
144
  except Exception as e:
145
  return f"오류가 발생했습니다: {str(e)}"
146
 
147
-
148
  def respond_deepseek_qna(
149
  question: str,
150
  system_message: str,
@@ -180,7 +129,6 @@ def respond_deepseek_qna(
180
  except Exception as e:
181
  return f"오류가 발생했습니다: {str(e)}"
182
 
183
-
184
  def respond_claude_qna(
185
  question: str,
186
  system_message: str,
@@ -221,7 +169,6 @@ def respond_claude_qna(
221
  except Exception as e:
222
  return f"예상치 못한 오류가 발생했습니다: {str(e)}"
223
 
224
-
225
  #############################
226
  # [기본코드] UI 부분 - 수정/삭제 불가
227
  #############################
@@ -229,68 +176,6 @@ def respond_claude_qna(
229
  with gr.Blocks() as demo:
230
  gr.Markdown("# LLM 플레이그라운드")
231
 
232
- #################
233
- # 일반 모델 탭
234
- #################
235
- with gr.Tab("일반 모델"):
236
- # 모델명 선택
237
- model_name = gr.Radio(
238
- choices=list(MODELS.keys()),
239
- label="Language Model (HuggingFace)",
240
- value="Zephyr 7B Beta"
241
- )
242
-
243
- # 입력1 ~ 입력5 (세로로 하나씩)
244
- input1 = gr.Textbox(label="입력1", lines=1)
245
- input2 = gr.Textbox(label="입력2", lines=1)
246
- input3 = gr.Textbox(label="입력3", lines=1)
247
- input4 = gr.Textbox(label="입력4", lines=1)
248
- input5 = gr.Textbox(label="입력5", lines=1)
249
-
250
- # 결과
251
- answer_output = gr.Textbox(label="결과", lines=5, interactive=False)
252
-
253
- # 고급 설정 - System Message를 Max Tokens 위로 이동
254
- with gr.Accordion("고급 설정 (일반 모델)", open=False):
255
- system_message = gr.Textbox(
256
- value="""반드시 한글로 답변할 것.
257
- 너는 최고의 비서이다.
258
- 내가 요구하는것들을 최대한 자세하고 정확하게 답변하라.
259
- """,
260
- label="System Message",
261
- lines=3
262
- )
263
- max_tokens = gr.Slider(minimum=0, maximum=2000, value=500, step=100, label="Max Tokens")
264
- temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
265
- top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
266
-
267
- submit_button = gr.Button("전송")
268
-
269
- def merge_and_call_hf(i1, i2, i3, i4, i5, m_name, mt, temp, top_p_, sys_msg):
270
- # 입력1~5를 공백 기준으로 합쳐서 question 구성
271
- question = " ".join([i1, i2, i3, i4, i5])
272
- return respond_hf_qna(
273
- question=question,
274
- model_name=m_name,
275
- max_tokens=mt,
276
- temperature=temp,
277
- top_p=top_p_,
278
- system_message=sys_msg
279
- )
280
-
281
- submit_button.click(
282
- fn=merge_and_call_hf,
283
- inputs=[
284
- input1, input2, input3, input4, input5,
285
- model_name,
286
- max_tokens,
287
- temperature,
288
- top_p,
289
- system_message
290
- ],
291
- outputs=answer_output
292
- )
293
-
294
  #################
295
  # Cohere Command R+ 탭
296
  #################
@@ -508,4 +393,4 @@ with gr.Blocks() as demo:
508
  # 메인 실행부
509
  #############################
510
  if __name__ == "__main__":
511
- demo.launch()
 
9
  # [기본코드] - 수정/삭제 불가
10
  #############################
11
 
 
 
 
 
 
 
 
 
 
 
12
  # Cohere Command R+ 모델 ID 정의
13
  COHERE_MODEL = "CohereForAI/c4ai-command-r-plus-08-2024"
14
 
 
21
  if not hf_token:
22
  raise ValueError("HuggingFace API 토큰이 필요합니다.")
23
 
24
+ if model_name == "Cohere Command R+":
 
 
25
  model_id = COHERE_MODEL
26
  else:
27
  raise ValueError("유효하지 않은 모델 이름입니다.")
28
  return InferenceClient(model_id, token=hf_token)
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def respond_cohere_qna(
31
  question: str,
32
  system_message: str,
 
60
  except Exception as e:
61
  return f"오류가 발생했습니다: {str(e)}"
62
 
 
63
  def respond_chatgpt_qna(
64
  question: str,
65
  system_message: str,
 
94
  except Exception as e:
95
  return f"오류가 발생했습니다: {str(e)}"
96
 
 
97
  def respond_deepseek_qna(
98
  question: str,
99
  system_message: str,
 
129
  except Exception as e:
130
  return f"오류가 발생했습니다: {str(e)}"
131
 
 
132
  def respond_claude_qna(
133
  question: str,
134
  system_message: str,
 
169
  except Exception as e:
170
  return f"예상치 못한 오류가 발생했습니다: {str(e)}"
171
 
 
172
  #############################
173
  # [기본코드] UI 부분 - 수정/삭제 불가
174
  #############################
 
176
  with gr.Blocks() as demo:
177
  gr.Markdown("# LLM 플레이그라운드")
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  #################
180
  # Cohere Command R+ 탭
181
  #################
 
393
  # 메인 실행부
394
  #############################
395
  if __name__ == "__main__":
396
+ demo.launch()