Sangwon78 commited on
Commit
49321a4
ยท
verified ยท
1 Parent(s): 92e4602

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -14
app.py CHANGED
@@ -17,7 +17,7 @@ openai.api_key = os.getenv("OPENAI_API_KEY").strip()
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},
@@ -62,7 +62,20 @@ def analyze_texts(difficulties, goals):
62
  # 2) SWOT ๋ถ„์„
63
  ######################
64
  def analyze_swot(strengths, weaknesses, opportunities, threats):
65
- system_message = "๋‹น์‹ ์€ swot ๋ถ„์„ ์ „๋ฌธ๊ฐ€์ž…๋‹ˆ๋‹ค. ์ž…๋ ฅ๋œ ๊ฐ•์ , ์•ฝ์ , ๊ธฐํšŒ, ์œ„ํ˜‘์„ ์š”์•ฝํ•˜์„ธ์š”."
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  content = f"""
67
  ๊ฐ•์ : {strengths}
68
  ์•ฝ์ : {weaknesses}
@@ -184,9 +197,9 @@ def run_all_in_one(
184
  ):
185
  """
186
  1) GPT: ์• ๋กœ์‚ฌํ•ญ/๋ชฉํ‘œ
187
- 2) GPT: SWOT
188
- 3) GPT: ์žฌ๋ฌด
189
- 4) GPT: ์ƒ๊ถŒ
190
  => ๋ชจ๋‘ EXE.xlsx์— ๊ธฐ์ž…, ์ตœ์ข… ํŒŒ์ผ ๋ฐ˜ํ™˜
191
  """
192
 
@@ -195,12 +208,24 @@ def run_all_in_one(
195
 
196
  ########## 2) GPT ํ˜ธ์ถœ(SWOT)
197
  swot_result = analyze_swot(strengths_input, weaknesses_input, opportunities_input, threats_input)
 
 
 
 
 
 
 
 
 
 
 
198
 
199
  ########## 3) GPT ํ˜ธ์ถœ(์žฌ๋ฌด)
200
  fin_result = analyze_financials(
201
  avg_monthly_sales, rent, labor_cost, management_cost,
202
  utilities, current_interest, other_cost, cost_ratio
203
  )
 
204
 
205
  ########## 4) GPT ํ˜ธ์ถœ(์ƒ๊ถŒ)
206
  market_result = analyze_market(region_input, industry_input)
@@ -242,7 +267,7 @@ def run_all_in_one(
242
  ws["G7"] = consulting_region
243
  ws["G7"].alignment = Alignment(horizontal="center", vertical="center")
244
 
245
- # (B) ์• ๋กœ์‚ฌํ•ญ/๋ชฉํ‘œ -> ์˜ˆ: D11, D22
246
  ws["D11"] = preview_difficulties
247
  ws["D22"] = preview_goals
248
  ws["D11"].alignment = Alignment(wrap_text=True)
@@ -267,16 +292,25 @@ def run_all_in_one(
267
  img_for_excel_2.height = int(37.79 * 5)
268
  ws.add_image(img_for_excel_2, "F117")
269
 
270
- # (C) SWOT ๊ฒฐ๊ณผ -> ์˜ˆ: D45:H45
271
  ws.merge_cells("D45:H45")
272
- ws["D45"] = swot_result
273
  ws["D45"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
274
 
275
- # (D) ์žฌ๋ฌด๋ถ„์„ ๊ฒฐ๊ณผ -> ์˜ˆ: E87:G87.. E90.. etc.
276
- # fin_result(๋ฌธ์ž์—ด)์— "๊ฐ๊ฐ€์ƒ๊ฐ๋น„: XXX" ์ด๋Ÿฐ ์‹ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •
277
- # ๊ฐ„๋‹จ ํŒŒ์‹ฑ ์˜ˆ (์‹ค์ œ๋ก  ์ •๊ทœ์‹ ๋“ฑ์œผ๋กœ ๊ฐ ์ค„ ์ฐพ์•„์„œ D87.. etc. ๋ฐฐ์น˜)
 
 
 
 
 
 
 
 
 
 
278
  lines = fin_result.split("\n")
279
- # ์˜ˆ์‹œ๋กœ D87=lines[0], D88=lines[1], ...
280
  ws.merge_cells("E87:G87")
281
  ws["E87"] = lines[0] if len(lines) > 0 else ""
282
  ws["E87"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
@@ -293,12 +327,12 @@ def run_all_in_one(
293
  ws["E90"] = lines[3] if len(lines) > 3 else ""
294
  ws["E90"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
295
 
296
- # (E) ์ƒ๊ถŒ๋ถ„์„ ๊ฒฐ๊ณผ -> ์˜ˆ: D101:H101
297
  ws.merge_cells("D101:H101")
298
  ws["D101"] = market_result
299
  ws["D101"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
300
 
301
- # ์ €์žฅ
302
  output = BytesIO()
303
  wb.save(output)
304
  output.seek(0)
 
17
  ######################
18
  def call_api(content, system_message, max_tokens, temperature, top_p):
19
  response = openai.ChatCompletion.create(
20
+ model="gpt-4o-mini", # ๊ธฐ์กด ๊ตฌ๋ฒ„์ „ API ํ˜•์‹
21
  messages=[
22
  {"role": "system", "content": system_message},
23
  {"role": "user", "content": content},
 
62
  # 2) SWOT ๋ถ„์„
63
  ######################
64
  def analyze_swot(strengths, weaknesses, opportunities, threats):
65
+ """
66
+ ๊ธฐ์กด์—๋Š” swot_result๋ฅผ ํ•œ ์ค„๋กœ ๋„ฃ์—ˆ๋‹ค๋ฉด,
67
+ ์—ฌ๊ธฐ์„œ๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ๊ฐ•์ , ์•ฝ์ , ๊ธฐํšŒ, ์œ„ํ˜‘์„ 4์ค„๋กœ ์ •๋ฆฌํ•ด ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๊ตฌ์„ฑ.
68
+ """
69
+ system_message = (
70
+ "๋‹น์‹ ์€ swot ๋ถ„์„ ์ „๋ฌธ๊ฐ€์ž…๋‹ˆ๋‹ค. "
71
+ "์ž…๋ ฅ๋œ ๊ฐ•์ , ์•ฝ์ , ๊ธฐํšŒ, ์œ„ํ˜‘์„ ๊ฐ๊ฐ ์š”์•ฝํ•ด ์ฃผ์„ธ์š”. "
72
+ "์ถœ๋ ฅ์€ ๋ฐ˜๋“œ์‹œ ์•„๋ž˜ ์˜ˆ์‹œ ํ˜•ํƒœ๋กœ 4์ค„๋งŒ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค:\n\n"
73
+ "๊ฐ•์ : ~~~\n"
74
+ "์•ฝ์ : ~~~\n"
75
+ "๊ธฐํšŒ: ~~~\n"
76
+ "์œ„ํ˜‘: ~~~\n\n"
77
+ "ํ•ญ์ƒ '๊ฐ•์ :', '์•ฝ์ :', '๊ธฐํšŒ:', '์œ„ํ˜‘:'์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” 4์ค„๋กœ๋งŒ ์‘๋‹ตํ•ด ์ฃผ์„ธ์š”."
78
+ )
79
  content = f"""
80
  ๊ฐ•์ : {strengths}
81
  ์•ฝ์ : {weaknesses}
 
197
  ):
198
  """
199
  1) GPT: ์• ๋กœ์‚ฌํ•ญ/๋ชฉํ‘œ
200
+ 2) GPT: SWOT(4์นธ)
201
+ 3) GPT: ์žฌ๋ฌด(4์ค„)
202
+ 4) GPT: ์ƒ๊ถŒ(1์ค„)
203
  => ๋ชจ๋‘ EXE.xlsx์— ๊ธฐ์ž…, ์ตœ์ข… ํŒŒ์ผ ๋ฐ˜ํ™˜
204
  """
205
 
 
208
 
209
  ########## 2) GPT ํ˜ธ์ถœ(SWOT)
210
  swot_result = analyze_swot(strengths_input, weaknesses_input, opportunities_input, threats_input)
211
+ # ์˜ˆ) swot_result:
212
+ # ๊ฐ•์ : ~~~
213
+ # ์•ฝ์ : ~~~
214
+ # ๊ธฐํšŒ: ~~~
215
+ # ์œ„ํ˜‘: ~~~
216
+ swot_lines = swot_result.split("\n")
217
+ # ๋„ค ์ค„์„ ๊ฐ๊ฐ ์ฐพ์•„์„œ ์ €์žฅ
218
+ strength_line = next((line for line in swot_lines if line.startswith("๊ฐ•์ :")), "")
219
+ weakness_line = next((line for line in swot_lines if line.startswith("์•ฝ์ :")), "")
220
+ opportunity_line = next((line for line in swot_lines if line.startswith("๊ธฐํšŒ:")), "")
221
+ threat_line = next((line for line in swot_lines if line.startswith("์œ„ํ˜‘:")), "")
222
 
223
  ########## 3) GPT ํ˜ธ์ถœ(์žฌ๋ฌด)
224
  fin_result = analyze_financials(
225
  avg_monthly_sales, rent, labor_cost, management_cost,
226
  utilities, current_interest, other_cost, cost_ratio
227
  )
228
+ # ์˜ˆ: 4์ค„ (๊ฐ๊ฐ€์ƒ๊ฐ๋น„/์ˆœ์ด์ต์œจ/์›”์ˆœ์ˆ˜์ต/์†์ต๋ถ„๊ธฐ์ )
229
 
230
  ########## 4) GPT ํ˜ธ์ถœ(์ƒ๊ถŒ)
231
  market_result = analyze_market(region_input, industry_input)
 
267
  ws["G7"] = consulting_region
268
  ws["G7"].alignment = Alignment(horizontal="center", vertical="center")
269
 
270
+ # (B) ์• ๋กœ์‚ฌํ•ญ/๋ชฉํ‘œ -> D11, D22
271
  ws["D11"] = preview_difficulties
272
  ws["D22"] = preview_goals
273
  ws["D11"].alignment = Alignment(wrap_text=True)
 
292
  img_for_excel_2.height = int(37.79 * 5)
293
  ws.add_image(img_for_excel_2, "F117")
294
 
295
+ # (C) SWOT ๊ฒฐ๊ณผ -> 4์ค„๋กœ ๋‚˜๋ˆ  D45:H45 / D54:H54 / D63:H63 / D72:H72
296
  ws.merge_cells("D45:H45")
297
+ ws["D45"] = strength_line
298
  ws["D45"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
299
 
300
+ ws.merge_cells("D54:H54")
301
+ ws["D54"] = weakness_line
302
+ ws["D54"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
303
+
304
+ ws.merge_cells("D63:H63")
305
+ ws["D63"] = opportunity_line
306
+ ws["D63"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
307
+
308
+ ws.merge_cells("D72:H72")
309
+ ws["D72"] = threat_line
310
+ ws["D72"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
311
+
312
+ # (D) ์žฌ๋ฌด๋ถ„์„ ๊ฒฐ๊ณผ(4์ค„) -> E87~E90
313
  lines = fin_result.split("\n")
 
314
  ws.merge_cells("E87:G87")
315
  ws["E87"] = lines[0] if len(lines) > 0 else ""
316
  ws["E87"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
 
327
  ws["E90"] = lines[3] if len(lines) > 3 else ""
328
  ws["E90"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
329
 
330
+ # (E) ์ƒ๊ถŒ๋ถ„์„ ๊ฒฐ๊ณผ -> D101:H101
331
  ws.merge_cells("D101:H101")
332
  ws["D101"] = market_result
333
  ws["D101"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
334
 
335
+ # ์ตœ์ข… ์ €์žฅ
336
  output = BytesIO()
337
  wb.save(output)
338
  output.seek(0)