aliceblue11 commited on
Commit
e72083d
·
verified ·
1 Parent(s): 54b7ed6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -21,9 +21,31 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
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
 
@@ -32,7 +54,8 @@ with gr.Blocks() as demo:
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)
@@ -64,6 +87,7 @@ with gr.Blocks() as demo:
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()
 
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
+ # 엑셀 업로드 후 처리 기능 추가
25
  def upload_excel(file):
26
  df = pd.read_excel(file.name)
27
+
28
+ # 1. G1셀에 "글자수" 입력
29
+ df.loc[0, 'G'] = "글자수"
30
+
31
+ # 2. G2셀부터 G열에 D열의 글자수 입력
32
+ df['G'] = df['D'].apply(lambda x: len(str(x)) if pd.notnull(x) else 0)
33
+
34
+ # 3. G열 기준으로 내림차순 정렬
35
+ df = df.sort_values(by='G', ascending=False)
36
+
37
+ # 4. 긍정 리뷰 10개 선택 (리뷰점수 E열이 5점 또는 4점이고, G열의 글자수가 500 이하인 항목)
38
+ positive_reviews = df[(df['E'].isin([5, 4])) & (df['G'] <= 500)].head(10)
39
+
40
+ # 5. 부정 리뷰 10개 선택 (리뷰점수 E열이 1점 또는 2점이고, G열의 글자수가 500 이하인 항목)
41
+ negative_reviews = df[(df['E'].isin([1, 2])) & (df['G'] <= 500)].head(10)
42
+
43
+ # 6. 긍정리뷰와 부정리뷰에서 리뷰날짜, 옵션, 리뷰내용(D열)을 선택하여 반환
44
+ positive_reviews_data = positive_reviews[['리뷰날짜', '옵션', 'D']]
45
+ negative_reviews_data = negative_reviews[['리뷰날짜', '옵션', 'D']]
46
+
47
+ # 긍정리뷰와 부정리뷰 내용을 텍스트 형식으로 반환 (그리디오에 보여주기 위해)
48
+ return positive_reviews_data.to_string(), negative_reviews_data.to_string()
49
 
50
  title = "AI 텍스트 생성기"
51
 
 
54
 
55
  # 엑셀 업로드 기능을 가장 위로 위치
56
  excel_input = gr.File(label="엑셀 파일 업로드", file_types=[".xls", ".xlsx"])
57
+ excel_output_positive = gr.Textbox(label="긍정리뷰 10개", lines=10)
58
+ excel_output_negative = gr.Textbox(label="부정리뷰 10개", lines=10)
59
 
60
  # 사용자 메시지의 명칭을 '긍정리뷰 10개'로 설정
61
  user_message = gr.Textbox(label="긍정리뷰 10개", lines=5)
 
87
  inputs=[user_message, system_message, max_tokens, temperature, top_p],
88
  outputs=[output1, output2])
89
 
90
+ # 엑셀 파일 업로드 후 긍정리뷰 10개와 부정리뷰 10개를 출력
91
+ excel_input.upload(upload_excel, inputs=[excel_input], outputs=[excel_output_positive, excel_output_negative])
92
 
93
+ demo.launch()