Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,9 @@ import openai
|
|
| 4 |
import anthropic
|
| 5 |
import os
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
def get_client(model_name: str):
|
| 8 |
"""
|
| 9 |
모델 이름에 맞춰 InferenceClient 생성.
|
|
@@ -13,10 +16,8 @@ def get_client(model_name: str):
|
|
| 13 |
if not hf_token:
|
| 14 |
raise ValueError("HuggingFace API 토큰이 필요합니다. (환경변수 HF_TOKEN 미설정)")
|
| 15 |
|
| 16 |
-
if model_name == "
|
| 17 |
-
model_id =
|
| 18 |
-
elif model_name == "c4ai-command-r-08-2024":
|
| 19 |
-
model_id = "CohereForAI/c4ai-command-r-08-2024"
|
| 20 |
else:
|
| 21 |
raise ValueError("유효하지 않은 모델 이름입니다.")
|
| 22 |
return InferenceClient(model_id, token=hf_token)
|
|
@@ -25,7 +26,6 @@ def cohere_respond(
|
|
| 25 |
message,
|
| 26 |
chat_history,
|
| 27 |
system_message,
|
| 28 |
-
cohere_model_choice,
|
| 29 |
max_tokens,
|
| 30 |
temperature,
|
| 31 |
top_p,
|
|
@@ -34,7 +34,7 @@ def cohere_respond(
|
|
| 34 |
Cohere Command R+ 모델 응답 함수.
|
| 35 |
HF 토큰은 함수 내부에서 os.environ을 통해 불러온다.
|
| 36 |
"""
|
| 37 |
-
model_name =
|
| 38 |
try:
|
| 39 |
client = get_client(model_name)
|
| 40 |
except ValueError as e:
|
|
@@ -223,7 +223,7 @@ with gr.Blocks() as demo:
|
|
| 223 |
# 일반 모델 관련 UI/기능 제거 (요청 사항에 따라 삭제)
|
| 224 |
# --------------------------------------------------
|
| 225 |
|
| 226 |
-
# Cohere Command R+
|
| 227 |
with gr.Tab("Cohere Command R+"):
|
| 228 |
with gr.Row():
|
| 229 |
cohere_system_message = gr.Textbox(
|
|
@@ -234,11 +234,6 @@ with gr.Blocks() as demo:
|
|
| 234 |
label="System Message",
|
| 235 |
lines=3
|
| 236 |
)
|
| 237 |
-
cohere_model_choice = gr.Radio(
|
| 238 |
-
choices=["c4ai-command-r-plus-08-2024", "c4ai-command-r-08-2024"],
|
| 239 |
-
value="c4ai-command-r-plus-08-2024",
|
| 240 |
-
label="모델 선택"
|
| 241 |
-
)
|
| 242 |
cohere_max_tokens = gr.Slider(minimum=100, maximum=8000, value=2000, step=100, label="Max new tokens")
|
| 243 |
cohere_temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
| 244 |
cohere_top_p = gr.Slider(
|
|
@@ -259,7 +254,6 @@ with gr.Blocks() as demo:
|
|
| 259 |
cohere_msg,
|
| 260 |
cohere_chatbot,
|
| 261 |
cohere_system_message,
|
| 262 |
-
cohere_model_choice,
|
| 263 |
cohere_max_tokens,
|
| 264 |
cohere_temperature,
|
| 265 |
cohere_top_p
|
|
@@ -268,7 +262,7 @@ with gr.Blocks() as demo:
|
|
| 268 |
cohere_submit_button.click(cohere_respond, inputs_for_cohere, cohere_chatbot)
|
| 269 |
cohere_clear_button.click(clear_conversation, outputs=cohere_chatbot, queue=False)
|
| 270 |
|
| 271 |
-
# ChatGPT
|
| 272 |
with gr.Tab("ChatGPT"):
|
| 273 |
with gr.Row():
|
| 274 |
chatgpt_system_message = gr.Textbox(
|
|
@@ -307,7 +301,7 @@ with gr.Blocks() as demo:
|
|
| 307 |
chatgpt_submit_button.click(chatgpt_respond, inputs_for_chatgpt, chatgpt_chatbot)
|
| 308 |
chatgpt_clear_button.click(clear_conversation, outputs=chatgpt_chatbot, queue=False)
|
| 309 |
|
| 310 |
-
# Claude
|
| 311 |
with gr.Tab("Claude"):
|
| 312 |
with gr.Row():
|
| 313 |
claude_system_message = gr.Textbox(
|
|
@@ -346,7 +340,7 @@ with gr.Blocks() as demo:
|
|
| 346 |
claude_submit_button.click(claude_respond, inputs_for_claude, claude_chatbot)
|
| 347 |
claude_clear_button.click(clear_conversation, outputs=claude_chatbot, queue=False)
|
| 348 |
|
| 349 |
-
# DeepSeek
|
| 350 |
with gr.Tab("DeepSeek"):
|
| 351 |
with gr.Row():
|
| 352 |
deepseek_system_message = gr.Textbox(
|
|
@@ -387,9 +381,10 @@ with gr.Blocks() as demo:
|
|
| 387 |
deepseek_temperature,
|
| 388 |
deepseek_top_p
|
| 389 |
]
|
|
|
|
| 390 |
deepseek_msg.submit(deepseek_respond, inputs_for_deepseek, deepseek_chatbot)
|
| 391 |
deepseek_submit_button.click(deepseek_respond, inputs_for_deepseek, deepseek_chatbot)
|
| 392 |
deepseek_clear_button.click(clear_conversation, outputs=deepseek_chatbot, queue=False)
|
| 393 |
|
| 394 |
if __name__ == "__main__":
|
| 395 |
-
demo.launch()
|
|
|
|
| 4 |
import anthropic
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# Cohere Command R+ 모델 ID 정의
|
| 8 |
+
COHERE_MODEL = "CohereForAI/c4ai-command-r-plus-08-2024"
|
| 9 |
+
|
| 10 |
def get_client(model_name: str):
|
| 11 |
"""
|
| 12 |
모델 이름에 맞춰 InferenceClient 생성.
|
|
|
|
| 16 |
if not hf_token:
|
| 17 |
raise ValueError("HuggingFace API 토큰이 필요합니다. (환경변수 HF_TOKEN 미설정)")
|
| 18 |
|
| 19 |
+
if model_name == "Cohere Command R+":
|
| 20 |
+
model_id = COHERE_MODEL
|
|
|
|
|
|
|
| 21 |
else:
|
| 22 |
raise ValueError("유효하지 않은 모델 이름입니다.")
|
| 23 |
return InferenceClient(model_id, token=hf_token)
|
|
|
|
| 26 |
message,
|
| 27 |
chat_history,
|
| 28 |
system_message,
|
|
|
|
| 29 |
max_tokens,
|
| 30 |
temperature,
|
| 31 |
top_p,
|
|
|
|
| 34 |
Cohere Command R+ 모델 응답 함수.
|
| 35 |
HF 토큰은 함수 내부에서 os.environ을 통해 불러온다.
|
| 36 |
"""
|
| 37 |
+
model_name = "Cohere Command R+"
|
| 38 |
try:
|
| 39 |
client = get_client(model_name)
|
| 40 |
except ValueError as e:
|
|
|
|
| 223 |
# 일반 모델 관련 UI/기능 제거 (요청 사항에 따라 삭제)
|
| 224 |
# --------------------------------------------------
|
| 225 |
|
| 226 |
+
# Cohere Command R+
|
| 227 |
with gr.Tab("Cohere Command R+"):
|
| 228 |
with gr.Row():
|
| 229 |
cohere_system_message = gr.Textbox(
|
|
|
|
| 234 |
label="System Message",
|
| 235 |
lines=3
|
| 236 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
cohere_max_tokens = gr.Slider(minimum=100, maximum=8000, value=2000, step=100, label="Max new tokens")
|
| 238 |
cohere_temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
| 239 |
cohere_top_p = gr.Slider(
|
|
|
|
| 254 |
cohere_msg,
|
| 255 |
cohere_chatbot,
|
| 256 |
cohere_system_message,
|
|
|
|
| 257 |
cohere_max_tokens,
|
| 258 |
cohere_temperature,
|
| 259 |
cohere_top_p
|
|
|
|
| 262 |
cohere_submit_button.click(cohere_respond, inputs_for_cohere, cohere_chatbot)
|
| 263 |
cohere_clear_button.click(clear_conversation, outputs=cohere_chatbot, queue=False)
|
| 264 |
|
| 265 |
+
# ChatGPT
|
| 266 |
with gr.Tab("ChatGPT"):
|
| 267 |
with gr.Row():
|
| 268 |
chatgpt_system_message = gr.Textbox(
|
|
|
|
| 301 |
chatgpt_submit_button.click(chatgpt_respond, inputs_for_chatgpt, chatgpt_chatbot)
|
| 302 |
chatgpt_clear_button.click(clear_conversation, outputs=chatgpt_chatbot, queue=False)
|
| 303 |
|
| 304 |
+
# Claude
|
| 305 |
with gr.Tab("Claude"):
|
| 306 |
with gr.Row():
|
| 307 |
claude_system_message = gr.Textbox(
|
|
|
|
| 340 |
claude_submit_button.click(claude_respond, inputs_for_claude, claude_chatbot)
|
| 341 |
claude_clear_button.click(clear_conversation, outputs=claude_chatbot, queue=False)
|
| 342 |
|
| 343 |
+
# DeepSeek
|
| 344 |
with gr.Tab("DeepSeek"):
|
| 345 |
with gr.Row():
|
| 346 |
deepseek_system_message = gr.Textbox(
|
|
|
|
| 381 |
deepseek_temperature,
|
| 382 |
deepseek_top_p
|
| 383 |
]
|
| 384 |
+
# Textbox.submit에서는 stream 인자를 제거합니다.
|
| 385 |
deepseek_msg.submit(deepseek_respond, inputs_for_deepseek, deepseek_chatbot)
|
| 386 |
deepseek_submit_button.click(deepseek_respond, inputs_for_deepseek, deepseek_chatbot)
|
| 387 |
deepseek_clear_button.click(clear_conversation, outputs=deepseek_chatbot, queue=False)
|
| 388 |
|
| 389 |
if __name__ == "__main__":
|
| 390 |
+
demo.launch()
|