Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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) ์ ๋ก์ฌํญ/๋ชฉํ ->
|
| 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 ๊ฒฐ๊ณผ ->
|
| 271 |
ws.merge_cells("D45:H45")
|
| 272 |
-
ws["D45"] =
|
| 273 |
ws["D45"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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) ์๊ถ๋ถ์ ๊ฒฐ๊ณผ ->
|
| 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)
|