Spaces:
Runtime error
Runtime error
aliceblue11
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,30 +4,22 @@ import os
|
|
4 |
import pandas as pd
|
5 |
from huggingface_hub import InferenceClient
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
"Meta Llama 3.1 8B": "meta-llama/Meta-Llama-3.1-8B-Instruct",
|
11 |
-
"Meta-Llama 3.1 70B-Instruct": "meta-llama/Meta-Llama-3.1-70B-Instruct",
|
12 |
-
"Microsoft": "microsoft/Phi-3-mini-4k-instruct",
|
13 |
-
"Mixtral 8x7B": "mistralai/Mistral-7B-Instruct-v0.3",
|
14 |
-
"Mixtral Nous-Hermes": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
15 |
-
"Cohere Command R+": "CohereForAI/c4ai-command-r-plus",
|
16 |
-
"Aya-23-35B": "CohereForAI/aya-23-35B"
|
17 |
-
}
|
18 |
|
19 |
def create_client(model_name):
|
20 |
return InferenceClient(model_name, token=os.getenv("HF_TOKEN"))
|
21 |
|
22 |
-
def call_api(
|
23 |
-
client = create_client(
|
24 |
messages = [{"role": "system", "content": system_message}, {"role": "user", "content": content}]
|
25 |
random_seed = random.randint(0, 1000000)
|
26 |
response = client.chat_completion(messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, seed=random_seed)
|
27 |
return response.choices[0].message.content
|
28 |
|
29 |
-
def generate_text(
|
30 |
-
return call_api(
|
31 |
|
32 |
def upload_excel(file):
|
33 |
df = pd.read_excel(file.name)
|
@@ -42,12 +34,10 @@ with gr.Blocks() as demo:
|
|
42 |
excel_input = gr.File(label="엑셀 파일 업로드", file_types=[".xls", ".xlsx"])
|
43 |
excel_output = gr.Textbox(label="엑셀 내용 미리보기", lines=10)
|
44 |
|
45 |
-
model = gr.Radio(choices=list(MODELS.keys()), label="언어 모델 선택", value="Zephyr 7B Beta")
|
46 |
-
|
47 |
# 사용자 메시지의 명칭을 '긍정리뷰 10개'로 설정
|
48 |
user_message = gr.Textbox(label="긍정리뷰 10개", lines=5)
|
49 |
|
50 |
-
# 입력창 1의 명칭을 '부정리뷰 10개'로
|
51 |
input1 = gr.Textbox(label="부정리뷰 10개", lines=5)
|
52 |
|
53 |
# 시스템 메시지(프롬프트)의 명칭을 '긍정 프롬프트'로 설정
|
@@ -71,7 +61,7 @@ with gr.Blocks() as demo:
|
|
71 |
generate_btn = gr.Button("텍스트 생성하기")
|
72 |
|
73 |
generate_btn.click(fn=generate_text,
|
74 |
-
inputs=[
|
75 |
outputs=[output1, output2])
|
76 |
|
77 |
excel_input.upload(upload_excel, inputs=[excel_input], outputs=[excel_output])
|
|
|
4 |
import pandas as pd
|
5 |
from huggingface_hub import InferenceClient
|
6 |
|
7 |
+
# 하드코딩된 언어 모델 설정
|
8 |
+
MODEL_NAME = "Cohere Command R+"
|
9 |
+
MODEL_PATH = "CohereForAI/c4ai-command-r-plus"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def create_client(model_name):
|
12 |
return InferenceClient(model_name, token=os.getenv("HF_TOKEN"))
|
13 |
|
14 |
+
def call_api(content, system_message, max_tokens, temperature, top_p):
|
15 |
+
client = create_client(MODEL_PATH) # 모델을 하드코딩된 값으로 설정
|
16 |
messages = [{"role": "system", "content": system_message}, {"role": "user", "content": content}]
|
17 |
random_seed = random.randint(0, 1000000)
|
18 |
response = client.chat_completion(messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, seed=random_seed)
|
19 |
return response.choices[0].message.content
|
20 |
|
21 |
+
def generate_text(user_message, system_message, max_tokens, temperature, top_p):
|
22 |
+
return call_api(user_message, system_message, max_tokens, temperature, top_p)
|
23 |
|
24 |
def upload_excel(file):
|
25 |
df = pd.read_excel(file.name)
|
|
|
34 |
excel_input = gr.File(label="엑셀 파일 업로드", file_types=[".xls", ".xlsx"])
|
35 |
excel_output = gr.Textbox(label="엑셀 내용 미리보기", lines=10)
|
36 |
|
|
|
|
|
37 |
# 사용자 메시지의 명칭을 '긍정리뷰 10개'로 설정
|
38 |
user_message = gr.Textbox(label="긍정리뷰 10개", lines=5)
|
39 |
|
40 |
+
# 입력창 1의 명칭을 '부정리뷰 10개'로 설정
|
41 |
input1 = gr.Textbox(label="부정리뷰 10개", lines=5)
|
42 |
|
43 |
# 시스템 메시지(프롬프트)의 명칭을 '긍정 프롬프트'로 설정
|
|
|
61 |
generate_btn = gr.Button("텍스트 생성하기")
|
62 |
|
63 |
generate_btn.click(fn=generate_text,
|
64 |
+
inputs=[user_message, system_message, max_tokens, temperature, top_p],
|
65 |
outputs=[output1, output2])
|
66 |
|
67 |
excel_input.upload(upload_excel, inputs=[excel_input], outputs=[excel_output])
|