Sangwon78 commited on
Commit
a5ae75e
Β·
verified Β·
1 Parent(s): 53b538e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -17,7 +17,7 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
17
  ######################
18
  def call_api(content, system_message, max_tokens, temperature, top_p):
19
  response = openai.ChatCompletion.create(
20
- model="gpt-4o-mini",
21
  messages=[
22
  {"role": "system", "content": system_message},
23
  {"role": "user", "content": content},
@@ -32,26 +32,36 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
32
  # 뢄석 ν•¨μˆ˜
33
  ######################
34
  def analyze_texts(difficulties, goals):
 
 
 
 
 
35
  preview_difficulties = call_api(
36
  content=difficulties,
37
  system_message=(
38
- "μ‚¬μš©μžκ°€ μž…λ ₯ν•œ μ• λ‘œμ‚¬ν•­μ— λŒ€ν•΄ μ΅œμ†Œ 4쀄 μ΄μƒμœΌλ‘œ, "
39
- "ꡬ체적으둜 뢄석 및 ν•΄κ²°λ°©μ•ˆμ„ μ œμ‹œν•΄μ€˜."
 
40
  ),
41
  max_tokens=150,
42
  temperature=0.7,
43
  top_p=0.9,
44
  )
 
 
45
  preview_goals = call_api(
46
  content=goals,
47
  system_message=(
48
- "μ‚¬μš©μžκ°€ μž…λ ₯ν•œ μ»¨μ„€νŒ… λͺ©ν‘œλ₯Ό μ΅œμ†Œ 4쀄 μ΄μƒμœΌλ‘œ, "
49
- "ꡬ체적으둜 μš”μ•½ 및 μ‹€ν–‰λ°©μ•ˆμ„ μ œμ‹œν•΄μ€˜."
 
50
  ),
51
  max_tokens=150,
52
  temperature=0.7,
53
  top_p=0.9,
54
  )
 
55
  return preview_difficulties, preview_goals
56
 
57
  ######################
@@ -71,18 +81,14 @@ def generate_excel(photo1, photo2, preview_difficulties, preview_goals):
71
  for col in ["D", "E", "F", "G", "H"]:
72
  ws.column_dimensions[col].width = 8.4
73
 
74
- ############################
75
- # 사진 μ‚½μž…
76
- # (κ°€λ‘œ 5cm, μ„Έλ‘œ 5cm)
77
- ############################
78
- width_px = int(37.79 * 5) # 5cm
79
- height_px = int(37.79 * 5) # 5cm
80
 
81
  if photo1 is not None:
82
  img1_bytes = BytesIO()
83
  photo1.save(img1_bytes, format="PNG")
84
  img1_bytes.seek(0)
85
-
86
  img1_for_excel = ExcelImage(img1_bytes)
87
  img1_for_excel.width = width_px
88
  img1_for_excel.height = height_px
@@ -92,7 +98,6 @@ def generate_excel(photo1, photo2, preview_difficulties, preview_goals):
92
  img2_bytes = BytesIO()
93
  photo2.save(img2_bytes, format="PNG")
94
  img2_bytes.seek(0)
95
-
96
  img2_for_excel = ExcelImage(img2_bytes)
97
  img2_for_excel.width = width_px
98
  img2_for_excel.height = height_px
 
17
  ######################
18
  def call_api(content, system_message, max_tokens, temperature, top_p):
19
  response = openai.ChatCompletion.create(
20
+ model="gpt-4o-mini", # μš”μ²­μ‚¬ν•­λŒ€λ‘œ gpt-4o-mini μ‚¬μš©
21
  messages=[
22
  {"role": "system", "content": system_message},
23
  {"role": "user", "content": content},
 
32
  # 뢄석 ν•¨μˆ˜
33
  ######################
34
  def analyze_texts(difficulties, goals):
35
+ """
36
+ μ‚¬μš©μž μž…λ ₯(μ• λ‘œμ‚¬ν•­, μ»¨μ„€νŒ… λͺ©ν‘œ)을 gpt-4o-mini둜 뢄석 ν›„
37
+ κ²°κ³Ό(미리보기)λ₯Ό 리턴
38
+ """
39
+ # μ• λ‘œμ‚¬ν•­ 뢄석
40
  preview_difficulties = call_api(
41
  content=difficulties,
42
  system_message=(
43
+ "μ‚¬μš©μžκ°€ μž…λ ₯ν•œ μ• λ‘œμ‚¬ν•­μ— λŒ€ν•΄ μ΅œμ†Œ 4쀄 μ΄μƒμœΌλ‘œ, ꡬ체적으둜 뢄석 및 "
44
+ "ν•΄κ²°λ°©μ•ˆμ„ μ œμ‹œν•΄μ€˜. λ¬Έμž₯은 쀑간에 λŠκΈ°μ§€ μ•Šκ³ , λΆˆν•„μš”ν•œ λ‚˜μ—΄(ν•˜λ‚˜, λ‘˜) 등을 "
45
+ "λ„£μ§€ 말며, '~μŠ΅λ‹ˆλ‹€.' ν˜•νƒœλ‘œ μžμ—°μŠ€λŸ½κ²Œ λλ‚˜λ„λ‘ μž‘μ„±ν•΄μ€˜."
46
  ),
47
  max_tokens=150,
48
  temperature=0.7,
49
  top_p=0.9,
50
  )
51
+
52
+ # μ»¨μ„€νŒ… λͺ©ν‘œ 뢄석
53
  preview_goals = call_api(
54
  content=goals,
55
  system_message=(
56
+ "μ‚¬μš©μžκ°€ μž…λ ₯ν•œ μ»¨μ„€νŒ… λͺ©ν‘œλ₯Ό μ΅œμ†Œ 4쀄 μ΄μƒμœΌλ‘œ, ꡬ체적으둜 μš”μ•½ 및 "
57
+ "μ‹€ν–‰λ°©μ•ˆμ„ μ œμ‹œν•΄μ€˜. λ¬Έμž₯은 쀑간에 λŠκΈ°μ§€ μ•Šκ³ , λΆˆν•„μš”ν•œ λ‚˜μ—΄(ν•˜λ‚˜, λ‘˜) 등을 "
58
+ "λ„£μ§€ 말며, '~μŠ΅λ‹ˆλ‹€.' ν˜•νƒœλ‘œ μžμ—°μŠ€λŸ½κ²Œ λλ‚˜λ„λ‘ μž‘μ„±ν•΄μ€˜."
59
  ),
60
  max_tokens=150,
61
  temperature=0.7,
62
  top_p=0.9,
63
  )
64
+
65
  return preview_difficulties, preview_goals
66
 
67
  ######################
 
81
  for col in ["D", "E", "F", "G", "H"]:
82
  ws.column_dimensions[col].width = 8.4
83
 
84
+ # 사진(5cm x 5cm)
85
+ width_px = int(37.79 * 5)
86
+ height_px = int(37.79 * 5)
 
 
 
87
 
88
  if photo1 is not None:
89
  img1_bytes = BytesIO()
90
  photo1.save(img1_bytes, format="PNG")
91
  img1_bytes.seek(0)
 
92
  img1_for_excel = ExcelImage(img1_bytes)
93
  img1_for_excel.width = width_px
94
  img1_for_excel.height = height_px
 
98
  img2_bytes = BytesIO()
99
  photo2.save(img2_bytes, format="PNG")
100
  img2_bytes.seek(0)
 
101
  img2_for_excel = ExcelImage(img2_bytes)
102
  img2_for_excel.width = width_px
103
  img2_for_excel.height = height_px