Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,69 @@
|
|
1 |
-
import
|
|
|
2 |
import os
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
# 파일이 존재하는지 확인하는 코드 추가
|
8 |
-
if os.path.exists(file_path):
|
9 |
-
try:
|
10 |
-
# 파일이 존재하면 엑셀 파일을 읽어들임
|
11 |
-
df = pd.read_excel(file_path)
|
12 |
-
|
13 |
-
# 1. G1셀에 "글자수"를 입력
|
14 |
-
df.loc[0, 'G'] = "글자수"
|
15 |
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
|
|
27 |
|
28 |
-
|
29 |
-
positive_reviews_data = positive_reviews[['리뷰날짜', '옵션', 'D']] # D열이 리뷰내용
|
30 |
-
negative_reviews_data = negative_reviews[['리뷰날짜', '옵션', 'D']]
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
print(f"파일을 처리하는 중 오류가 발생했습니다: {e}")
|
46 |
-
else:
|
47 |
-
# 파일이 존재하지 않으면 에러 메시지 출력
|
48 |
-
print(f"Error: 파일을 찾을 수 없���니다. 경로를 확인해주세요: {file_path}")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
import os
|
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)
|
26 |
+
return df.head().to_string()
|
27 |
|
28 |
+
title = "AI 텍스트 생성기"
|
|
|
|
|
29 |
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown(f"# {title}")
|
32 |
+
|
33 |
+
# 엑셀 업로드 기능을 가장 위로 위치
|
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 |
+
# 시스템 메시지(프롬프트)의 명칭을 '긍정 프롬프트'로 설정
|
44 |
+
system_message = gr.Textbox(label="긍정 프롬프트", lines=10)
|
45 |
|
46 |
+
# 입력창 2의 명칭을 '부정 프롬프트'로 설정
|
47 |
+
input2 = gr.Textbox(label="부정 프롬프트")
|
48 |
+
|
49 |
+
# 출력창 1의 명칭을 '긍정리뷰분석'으로 설정
|
50 |
+
output1 = gr.Textbox(label="긍정리뷰분석", lines=10)
|
51 |
+
|
52 |
+
# 출력창 2의 명칭을 '부정리뷰분석'으로 설정
|
53 |
+
output2 = gr.Textbox(label="부정리뷰분석", lines=10)
|
54 |
|
55 |
+
with gr.Accordion("고급 설정", open=False):
|
56 |
+
max_tokens = gr.Slider(label="Max Tokens", minimum=0, maximum=4000, value=500, step=100)
|
57 |
+
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.75, step=0.05)
|
58 |
+
top_p = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, value=0.95, step=0.05)
|
59 |
+
|
60 |
+
# 실행 버튼 추가
|
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])
|
68 |
|
69 |
+
demo.launch()
|
|
|
|
|
|
|
|