Update app.py
Browse files
app.py
CHANGED
|
@@ -27,10 +27,10 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
|
|
| 27 |
temperature=temperature,
|
| 28 |
top_p=top_p,
|
| 29 |
)
|
| 30 |
-
return response.choices[0].message[
|
| 31 |
|
| 32 |
############################
|
| 33 |
-
# (1) ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์ ํจ์
|
| 34 |
############################
|
| 35 |
def analyze_texts(difficulties, goals):
|
| 36 |
preview_difficulties = call_api(
|
|
@@ -60,15 +60,21 @@ def analyze_texts(difficulties, goals):
|
|
| 60 |
return preview_difficulties, preview_goals
|
| 61 |
|
| 62 |
############################
|
| 63 |
-
# (2) ์ฌ๋ฌด๋ถ์ (GPT
|
| 64 |
############################
|
| 65 |
def analyze_financials(
|
| 66 |
-
avg_monthly_sales,
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
):
|
| 69 |
"""
|
| 70 |
-
|
| 71 |
-
|
| 72 |
"""
|
| 73 |
system_message = (
|
| 74 |
"๋น์ ์ ์ธ๋ฌด์ฌ(ํ๊ณ์ฌ)์
๋๋ค. ์๋ ์
๋ ฅ๊ฐ์ ๋ฐํ์ผ๋ก ๊ณ์ฐํ ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, "
|
|
@@ -92,29 +98,20 @@ def analyze_financials(
|
|
| 92 |
3) ์์์์ต
|
| 93 |
4) ์์ต๋ถ๊ธฐ์
|
| 94 |
"""
|
| 95 |
-
|
| 96 |
content=content,
|
| 97 |
system_message=system_message,
|
| 98 |
max_tokens=1024,
|
| 99 |
temperature=0.7,
|
| 100 |
top_p=1.0
|
| 101 |
)
|
| 102 |
-
return gpt_result
|
| 103 |
|
| 104 |
############################
|
| 105 |
# ์ฌ๋ฌด๋ถ์ GPT ๊ฒฐ๊ณผ ํ์ฑ
|
| 106 |
############################
|
| 107 |
def parse_financial_result(gpt_result):
|
| 108 |
"""
|
| 109 |
-
|
| 110 |
-
dict๋ก ๋ฆฌํด:
|
| 111 |
-
{
|
| 112 |
-
"๊ฐ๊ฐ์๊ฐ๋น": "...",
|
| 113 |
-
"์์ด์ต์จ": "...",
|
| 114 |
-
"์์์์ต": "...",
|
| 115 |
-
"์์ต๋ถ๊ธฐ์ ": "..."
|
| 116 |
-
}
|
| 117 |
-
GPT ๋ต๋ณ ์:
|
| 118 |
๊ฐ๊ฐ์๊ฐ๋น: 1000
|
| 119 |
์์ด์ต์จ: 12%
|
| 120 |
์์์์ต: 300
|
|
@@ -127,11 +124,9 @@ def parse_financial_result(gpt_result):
|
|
| 127 |
"์์ต๋ถ๊ธฐ์ ": "",
|
| 128 |
}
|
| 129 |
|
| 130 |
-
# ๊ฐ ์ค ํ์ฑ(๊ฐ๋จ ์ ๊ท์ ๋๋ startswith๋ก ์ฒ๋ฆฌ)
|
| 131 |
lines = gpt_result.split("\n")
|
| 132 |
for line in lines:
|
| 133 |
line = line.strip()
|
| 134 |
-
# ์: "๊ฐ๊ฐ์๊ฐ๋น: 1000"
|
| 135 |
for key in result_dict:
|
| 136 |
if line.startswith(key + ":"):
|
| 137 |
val = line.split(":", 1)[1].strip()
|
|
@@ -139,7 +134,7 @@ def parse_financial_result(gpt_result):
|
|
| 139 |
return result_dict
|
| 140 |
|
| 141 |
############################
|
| 142 |
-
# (3) SWOT ๋ถ์
|
| 143 |
############################
|
| 144 |
def analyze_swot(strengths, weaknesses, opportunities, threats):
|
| 145 |
system_message = "๋น์ ์ swot ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ์ฉ์์ ๊ฐ์ , ์ฝ์ , ๊ธฐํ, ์ํ์ ๋ํด ๊ฒ์ํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๊ณตํฉ๋๋ค."
|
|
@@ -158,7 +153,7 @@ def analyze_swot(strengths, weaknesses, opportunities, threats):
|
|
| 158 |
)
|
| 159 |
|
| 160 |
############################
|
| 161 |
-
# (4) ์๊ถ ๋ถ์ (6์ค ์ด๋ด)
|
| 162 |
############################
|
| 163 |
def analyze_market(region, industry):
|
| 164 |
system_message = (
|
|
@@ -178,7 +173,7 @@ def analyze_market(region, industry):
|
|
| 178 |
)
|
| 179 |
|
| 180 |
############################
|
| 181 |
-
# (5) SWOT ๊ฒฐ๊ณผ๋ฅผ EXE.xlsx์
|
| 182 |
############################
|
| 183 |
def export_swot_excel(strengths, weaknesses, opportunities, threats):
|
| 184 |
wb = load_workbook("EXE.xlsx")
|
|
@@ -203,10 +198,12 @@ def export_swot_excel(strengths, weaknesses, opportunities, threats):
|
|
| 203 |
output = BytesIO()
|
| 204 |
wb.save(output)
|
| 205 |
output.seek(0)
|
|
|
|
| 206 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 207 |
tmp.write(output.getvalue())
|
| 208 |
tmp.flush()
|
| 209 |
temp_file_path = tmp.name
|
|
|
|
| 210 |
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 211 |
os.rename(temp_file_path, final_path)
|
| 212 |
return final_path
|
|
@@ -215,10 +212,9 @@ def run_export_swot_excel(strengths, weaknesses, opportunities, threats):
|
|
| 215 |
return export_swot_excel(strengths, weaknesses, opportunities, threats)
|
| 216 |
|
| 217 |
############################
|
| 218 |
-
# (6) ์ฌ๋ฌด๋ถ์
|
| 219 |
############################
|
| 220 |
def generate_financial_excel(
|
| 221 |
-
# (์
๋ ฅ) 8๊ฐ
|
| 222 |
avg_monthly_sales,
|
| 223 |
rent,
|
| 224 |
labor_cost,
|
|
@@ -229,12 +225,12 @@ def generate_financial_excel(
|
|
| 229 |
cost_ratio
|
| 230 |
):
|
| 231 |
"""
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
"""
|
| 237 |
-
# 1) GPT
|
| 238 |
gpt_raw = analyze_financials(
|
| 239 |
avg_monthly_sales,
|
| 240 |
rent,
|
|
@@ -245,81 +241,72 @@ def generate_financial_excel(
|
|
| 245 |
other_cost,
|
| 246 |
cost_ratio
|
| 247 |
)
|
| 248 |
-
parsed = parse_financial_result(gpt_raw)
|
| 249 |
|
| 250 |
-
# 2) ์์
๊ธฐ๋ก
|
| 251 |
wb = load_workbook("EXE.xlsx")
|
| 252 |
ws = wb.active
|
| 253 |
|
| 254 |
-
#
|
| 255 |
-
#
|
| 256 |
-
ws.merge_cells("
|
| 257 |
-
ws["
|
| 258 |
-
ws["
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
ws
|
| 262 |
-
ws["
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
ws.
|
| 267 |
-
|
| 268 |
-
ws
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
ws
|
| 273 |
-
ws["
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
ws.merge_cells("
|
| 277 |
-
ws["
|
| 278 |
-
ws["
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
ws
|
| 282 |
-
ws["
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
ws.
|
| 287 |
-
|
| 288 |
-
ws
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
ws
|
| 293 |
-
ws["
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
ws.merge_cells("
|
| 297 |
-
ws["
|
| 298 |
-
ws["
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
ws
|
| 302 |
-
ws["
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
# 11) ์์์ต(= ์์์์ต) -> D97:G97 (GPT)
|
| 306 |
-
ws.merge_cells("D97:G97")
|
| 307 |
-
ws["D97"] = f"์์์ต: {parsed['์์์์ต']}"
|
| 308 |
-
ws["D97"].alignment = Alignment(horizontal="center", vertical="center")
|
| 309 |
-
|
| 310 |
-
# 12) ์์ต๋ถ๊ธฐ์ -> D98:G98 (GPT)
|
| 311 |
-
ws.merge_cells("D98:G98")
|
| 312 |
-
ws["D98"] = f"์์ต๋ถ๊ธฐ์ : {parsed['์์ต๋ถ๊ธฐ์ ']}"
|
| 313 |
-
ws["D98"].alignment = Alignment(horizontal="center", vertical="center")
|
| 314 |
-
|
| 315 |
-
# 3) ์ ์ฅ -> EXE.xlsx
|
| 316 |
output = BytesIO()
|
| 317 |
wb.save(output)
|
| 318 |
output.seek(0)
|
|
|
|
| 319 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 320 |
tmp.write(output.getvalue())
|
| 321 |
tmp.flush()
|
| 322 |
temp_file_path = tmp.name
|
|
|
|
| 323 |
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 324 |
os.rename(temp_file_path, final_path)
|
| 325 |
return final_path
|
|
@@ -346,10 +333,8 @@ def run_generate_financial_excel(
|
|
| 346 |
)
|
| 347 |
|
| 348 |
############################
|
| 349 |
-
# (7)
|
| 350 |
-
# & UI ๋ก์ง์ ๊ธฐ์กด๊ณผ ๋์ผ
|
| 351 |
############################
|
| 352 |
-
|
| 353 |
def generate_excel(
|
| 354 |
consulting_company_rep,
|
| 355 |
consulting_address,
|
|
@@ -367,7 +352,6 @@ def generate_excel(
|
|
| 367 |
wb = load_workbook("EXE.xlsx")
|
| 368 |
ws = wb.active
|
| 369 |
|
| 370 |
-
# ์๋จ 8๊ฐ
|
| 371 |
ws.merge_cells("C4:E4")
|
| 372 |
ws["C4"] = consulting_company_rep
|
| 373 |
ws["C4"].alignment = Alignment(horizontal="center", vertical="center")
|
|
@@ -400,13 +384,11 @@ def generate_excel(
|
|
| 400 |
ws["G7"] = consulting_region
|
| 401 |
ws["G7"].alignment = Alignment(horizontal="center", vertical="center")
|
| 402 |
|
| 403 |
-
# ์ ๋ก์ฌํญ/๋ชฉํ
|
| 404 |
ws["D11"] = preview_difficulties
|
| 405 |
ws["D22"] = preview_goals
|
| 406 |
ws["D11"].alignment = Alignment(wrap_text=True)
|
| 407 |
ws["D22"].alignment = Alignment(wrap_text=True)
|
| 408 |
|
| 409 |
-
# ์ฌ์ง
|
| 410 |
width_px = int(37.79 * 5)
|
| 411 |
height_px = int(37.79 * 5)
|
| 412 |
|
|
@@ -431,10 +413,12 @@ def generate_excel(
|
|
| 431 |
output = BytesIO()
|
| 432 |
wb.save(output)
|
| 433 |
output.seek(0)
|
|
|
|
| 434 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 435 |
tmp.write(output.getvalue())
|
| 436 |
tmp.flush()
|
| 437 |
temp_file_path = tmp.name
|
|
|
|
| 438 |
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 439 |
os.rename(temp_file_path, final_path)
|
| 440 |
return final_path
|
|
@@ -471,14 +455,14 @@ def run_generate_excel(
|
|
| 471 |
)
|
| 472 |
|
| 473 |
############################
|
| 474 |
-
# Gradio UI
|
| 475 |
############################
|
| 476 |
def main():
|
| 477 |
with gr.Blocks() as demo:
|
| 478 |
-
gr.Markdown("## (๋จ์ผ ํ์ด์ง)
|
| 479 |
|
| 480 |
-
#
|
| 481 |
-
gr.Markdown("### ์๋จ 8๊ฐ ์ ๋ณด
|
| 482 |
with gr.Row():
|
| 483 |
consulting_company_rep = gr.Textbox(label="์ปจ์คํ
์
์ฒด๋ช
๋ฐ ๋ํ")
|
| 484 |
consulting_address = gr.Textbox(label="์ปจ์คํ
์ฃผ์")
|
|
@@ -493,34 +477,33 @@ def main():
|
|
| 493 |
|
| 494 |
gr.Markdown("---")
|
| 495 |
|
| 496 |
-
#
|
| 497 |
-
gr.Markdown("### ์ ๋ก์ฌํญ & ์ปจ์คํ
๋ชฉํ (GPT
|
| 498 |
with gr.Row():
|
| 499 |
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 500 |
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
| 501 |
-
|
| 502 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 503 |
preview_difficulties_output = gr.Textbox(label="์ ๋ก์ฌํญ ๋ถ์ ๊ฒฐ๊ณผ", lines=3)
|
| 504 |
preview_goals_output = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ๋ถ์ ๊ฒฐ๊ณผ", lines=3)
|
| 505 |
|
| 506 |
analyze_button.click(
|
| 507 |
-
fn=
|
| 508 |
inputs=[difficulties_input, goals_input],
|
| 509 |
outputs=[preview_difficulties_output, preview_goals_output]
|
| 510 |
)
|
| 511 |
|
| 512 |
gr.Markdown("---")
|
| 513 |
|
| 514 |
-
#
|
| 515 |
-
gr.Markdown("### ์ฌ์ง
|
| 516 |
with gr.Row():
|
| 517 |
photo_input_1 = gr.Image(label="์์ง์
์ฒด์ฌ์ง1", type="pil")
|
| 518 |
photo_input_2 = gr.Image(label="์์ง์
์ฒด์ฌ์ง2", type="pil")
|
| 519 |
|
| 520 |
gr.Markdown("---")
|
| 521 |
|
| 522 |
-
#
|
| 523 |
-
gr.Markdown("### SWOT ๋ถ์
|
| 524 |
strengths_input = gr.Textbox(label="๊ฐ์ ")
|
| 525 |
weaknesses_input = gr.Textbox(label="์ฝ์ ")
|
| 526 |
opportunities_input = gr.Textbox(label="๊ธฐํ")
|
|
@@ -534,8 +517,7 @@ def main():
|
|
| 534 |
outputs=swot_result_output
|
| 535 |
)
|
| 536 |
|
| 537 |
-
|
| 538 |
-
swot_excel_button = gr.Button("SWOT ๊ฒฐ๊ณผ๋ฅผ EXE.xlsx๋ก ๋ค์ด๋ก๋")
|
| 539 |
swot_excel_file = gr.File(label="SWOT_EXCEL ๋ค์ด๋ก๋")
|
| 540 |
swot_excel_button.click(
|
| 541 |
fn=run_export_swot_excel,
|
|
@@ -545,25 +527,23 @@ def main():
|
|
| 545 |
|
| 546 |
gr.Markdown("---")
|
| 547 |
|
| 548 |
-
#
|
| 549 |
-
gr.Markdown("### ์ฌ๋ฌด๋ถ์ (
|
| 550 |
with gr.Row():
|
| 551 |
avg_monthly_sales_input = gr.Textbox(label="์ํ๊ท ๋งค์ถ์ก")
|
|
|
|
| 552 |
labor_cost_input = gr.Textbox(label="์ธ๊ฑด๋น")
|
| 553 |
-
|
| 554 |
-
cost_ratio_input = gr.Textbox(label="์๊ฐ์จ")
|
| 555 |
|
| 556 |
with gr.Row():
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
current_interest_input = gr.Textbox(label="์ง๊ธ์ด์")
|
| 560 |
other_cost_input = gr.Textbox(label="๊ธฐํ๋น์ฉ")
|
|
|
|
| 561 |
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
financial_excel_button.click(
|
| 567 |
fn=run_generate_financial_excel,
|
| 568 |
inputs=[
|
| 569 |
avg_monthly_sales_input,
|
|
@@ -575,36 +555,32 @@ def main():
|
|
| 575 |
other_cost_input,
|
| 576 |
cost_ratio_input
|
| 577 |
],
|
| 578 |
-
outputs=[
|
| 579 |
)
|
| 580 |
|
| 581 |
gr.Markdown("---")
|
| 582 |
|
| 583 |
-
#
|
| 584 |
-
gr.Markdown("### ์๊ถ
|
| 585 |
region_input = gr.Textbox(label="์ง์ญ")
|
| 586 |
industry_input = gr.Textbox(label="์
์ข
")
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
analyze_button_market = gr.Button("์๊ถ๋ถ์")
|
| 590 |
-
|
| 591 |
analyze_button_market.click(
|
| 592 |
-
fn=
|
| 593 |
inputs=[region_input, industry_input],
|
| 594 |
outputs=result_output_market
|
| 595 |
)
|
| 596 |
|
| 597 |
gr.Markdown("---")
|
| 598 |
|
| 599 |
-
#
|
| 600 |
-
gr.Markdown("### ์๋จ8
|
| 601 |
-
final_excel_button = gr.Button("์ต์ข
|
| 602 |
-
final_excel_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญ
|
| 603 |
-
|
| 604 |
final_excel_button.click(
|
| 605 |
fn=run_generate_excel,
|
| 606 |
inputs=[
|
| 607 |
-
# ์๋จ 8๊ฐ
|
| 608 |
consulting_company_rep,
|
| 609 |
consulting_address,
|
| 610 |
consulting_field,
|
|
@@ -613,12 +589,8 @@ def main():
|
|
| 613 |
consulting_date_time,
|
| 614 |
consulting_round,
|
| 615 |
consulting_region,
|
| 616 |
-
|
| 617 |
-
# ์ฌ์ง
|
| 618 |
photo_input_1,
|
| 619 |
photo_input_2,
|
| 620 |
-
|
| 621 |
-
# ์ ๋ก์ฌํญ/๋ชฉํ
|
| 622 |
difficulties_input,
|
| 623 |
goals_input,
|
| 624 |
preview_difficulties_output,
|
|
|
|
| 27 |
temperature=temperature,
|
| 28 |
top_p=top_p,
|
| 29 |
)
|
| 30 |
+
return response.choices[0].message["content"]
|
| 31 |
|
| 32 |
############################
|
| 33 |
+
# (1) ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์ ํจ์
|
| 34 |
############################
|
| 35 |
def analyze_texts(difficulties, goals):
|
| 36 |
preview_difficulties = call_api(
|
|
|
|
| 60 |
return preview_difficulties, preview_goals
|
| 61 |
|
| 62 |
############################
|
| 63 |
+
# (2) ์ฌ๋ฌด ๋ถ์ ํจ์ (GPT)
|
| 64 |
############################
|
| 65 |
def analyze_financials(
|
| 66 |
+
avg_monthly_sales,
|
| 67 |
+
rent,
|
| 68 |
+
labor_cost,
|
| 69 |
+
management_cost,
|
| 70 |
+
utilities,
|
| 71 |
+
current_interest,
|
| 72 |
+
other_cost,
|
| 73 |
+
cost_ratio
|
| 74 |
):
|
| 75 |
"""
|
| 76 |
+
GPT๋ฅผ ํตํด ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, ์์์์ต, ์์ต๋ถ๊ธฐ์ โ '์ ๋ชฉ: ์์น' ํํ๋ก๋ง ๋ฐํ
|
| 77 |
+
(ํ๋ฉด์ ํ์ํ์ง ์๊ณ , ์์
์๋ง ๊ธฐ๋ก)
|
| 78 |
"""
|
| 79 |
system_message = (
|
| 80 |
"๋น์ ์ ์ธ๋ฌด์ฌ(ํ๊ณ์ฌ)์
๋๋ค. ์๋ ์
๋ ฅ๊ฐ์ ๋ฐํ์ผ๋ก ๊ณ์ฐํ ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, "
|
|
|
|
| 98 |
3) ์์์์ต
|
| 99 |
4) ์์ต๋ถ๊ธฐ์
|
| 100 |
"""
|
| 101 |
+
return call_api(
|
| 102 |
content=content,
|
| 103 |
system_message=system_message,
|
| 104 |
max_tokens=1024,
|
| 105 |
temperature=0.7,
|
| 106 |
top_p=1.0
|
| 107 |
)
|
|
|
|
| 108 |
|
| 109 |
############################
|
| 110 |
# ์ฌ๋ฌด๋ถ์ GPT ๊ฒฐ๊ณผ ํ์ฑ
|
| 111 |
############################
|
| 112 |
def parse_financial_result(gpt_result):
|
| 113 |
"""
|
| 114 |
+
์:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
๊ฐ๊ฐ์๊ฐ๋น: 1000
|
| 116 |
์์ด์ต์จ: 12%
|
| 117 |
์์์์ต: 300
|
|
|
|
| 124 |
"์์ต๋ถ๊ธฐ์ ": "",
|
| 125 |
}
|
| 126 |
|
|
|
|
| 127 |
lines = gpt_result.split("\n")
|
| 128 |
for line in lines:
|
| 129 |
line = line.strip()
|
|
|
|
| 130 |
for key in result_dict:
|
| 131 |
if line.startswith(key + ":"):
|
| 132 |
val = line.split(":", 1)[1].strip()
|
|
|
|
| 134 |
return result_dict
|
| 135 |
|
| 136 |
############################
|
| 137 |
+
# (3) SWOT ๋ถ์ ํจ์
|
| 138 |
############################
|
| 139 |
def analyze_swot(strengths, weaknesses, opportunities, threats):
|
| 140 |
system_message = "๋น์ ์ swot ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ์ฉ์์ ๊ฐ์ , ์ฝ์ , ๊ธฐํ, ์ํ์ ๋ํด ๊ฒ์ํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๊ณตํฉ๋๋ค."
|
|
|
|
| 153 |
)
|
| 154 |
|
| 155 |
############################
|
| 156 |
+
# (4) ์๊ถ ๋ถ์ ํจ์ (6์ค ์ด๋ด)
|
| 157 |
############################
|
| 158 |
def analyze_market(region, industry):
|
| 159 |
system_message = (
|
|
|
|
| 173 |
)
|
| 174 |
|
| 175 |
############################
|
| 176 |
+
# (5) SWOT ๊ฒฐ๊ณผ๋ฅผ EXE.xlsx์ ๊ธฐ์ฌ
|
| 177 |
############################
|
| 178 |
def export_swot_excel(strengths, weaknesses, opportunities, threats):
|
| 179 |
wb = load_workbook("EXE.xlsx")
|
|
|
|
| 198 |
output = BytesIO()
|
| 199 |
wb.save(output)
|
| 200 |
output.seek(0)
|
| 201 |
+
|
| 202 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 203 |
tmp.write(output.getvalue())
|
| 204 |
tmp.flush()
|
| 205 |
temp_file_path = tmp.name
|
| 206 |
+
|
| 207 |
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 208 |
os.rename(temp_file_path, final_path)
|
| 209 |
return final_path
|
|
|
|
| 212 |
return export_swot_excel(strengths, weaknesses, opportunities, threats)
|
| 213 |
|
| 214 |
############################
|
| 215 |
+
# (6) ์ฌ๋ฌด๋ถ์ โ EXE.xlsx (ํ๋ฉด ์ถ๋ ฅX)
|
| 216 |
############################
|
| 217 |
def generate_financial_excel(
|
|
|
|
| 218 |
avg_monthly_sales,
|
| 219 |
rent,
|
| 220 |
labor_cost,
|
|
|
|
| 225 |
cost_ratio
|
| 226 |
):
|
| 227 |
"""
|
| 228 |
+
12๊ฐ ํญ๋ชฉ:
|
| 229 |
+
์ํ๊ท ๋งค์ถ์ก, ์ธ๊ฑด๋น, ์๋๊ด์ด๋น, ๊ฐ๊ฐ์๊ฐ๋น, ์๊ฐ์จ,
|
| 230 |
+
์์ฐจ๋ฃ, ๊ด๋ฆฌ๋น, ์ง๊ธ์ด์, ๊ธฐํ๋น์ฉ, ์์ด์ต์จ, ์์์ต, ์์ต๋ถ๊ธฐ์
|
| 231 |
+
โ e87:f87:g87.. e98:f98:g98
|
| 232 |
"""
|
| 233 |
+
# (1) GPT๋ก ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, ์์์์ต, ์์ต๋ถ๊ธฐ์ ๋ฐ์์ค๊ธฐ
|
| 234 |
gpt_raw = analyze_financials(
|
| 235 |
avg_monthly_sales,
|
| 236 |
rent,
|
|
|
|
| 241 |
other_cost,
|
| 242 |
cost_ratio
|
| 243 |
)
|
| 244 |
+
parsed = parse_financial_result(gpt_raw)
|
| 245 |
|
| 246 |
+
# (2) ์์
์ ๊ธฐ๋ก
|
| 247 |
wb = load_workbook("EXE.xlsx")
|
| 248 |
ws = wb.active
|
| 249 |
|
| 250 |
+
# ๋ณํฉ + ๊ฐ์ด๋ฐ ์ ๋ ฌ + ๊ฐ ํ ๋น
|
| 251 |
+
# E87:F87:G87
|
| 252 |
+
ws.merge_cells("E87:G87")
|
| 253 |
+
ws["E87"] = f"์ํ๊ท ๋งค์ถ์ก: {avg_monthly_sales}"
|
| 254 |
+
ws["E87"].alignment = Alignment(horizontal="center", vertical="center")
|
| 255 |
+
|
| 256 |
+
ws.merge_cells("E88:G88")
|
| 257 |
+
ws["E88"] = f"์ธ๊ฑด๋น: {labor_cost}"
|
| 258 |
+
ws["E88"].alignment = Alignment(horizontal="center", vertical="center")
|
| 259 |
+
|
| 260 |
+
ws.merge_cells("E89:G89")
|
| 261 |
+
ws["E89"] = f"์๋๊ด์ด๋น: {utilities}"
|
| 262 |
+
ws["E89"].alignment = Alignment(horizontal="center", vertical="center")
|
| 263 |
+
|
| 264 |
+
ws.merge_cells("E90:G90")
|
| 265 |
+
ws["E90"] = f"๊ฐ๊ฐ์๊ฐ๋น: {parsed['๊ฐ๊ฐ์๊ฐ๋น']}"
|
| 266 |
+
ws["E90"].alignment = Alignment(horizontal="center", vertical="center")
|
| 267 |
+
|
| 268 |
+
ws.merge_cells("E91:G91")
|
| 269 |
+
ws["E91"] = f"์๊ฐ์จ: {cost_ratio}"
|
| 270 |
+
ws["E91"].alignment = Alignment(horizontal="center", vertical="center")
|
| 271 |
+
|
| 272 |
+
ws.merge_cells("E92:G92")
|
| 273 |
+
ws["E92"] = f"์์ฐจ๋ฃ: {rent}"
|
| 274 |
+
ws["E92"].alignment = Alignment(horizontal="center", vertical="center")
|
| 275 |
+
|
| 276 |
+
ws.merge_cells("E93:G93")
|
| 277 |
+
ws["E93"] = f"๊ด๋ฆฌ๋น: {management_cost}"
|
| 278 |
+
ws["E93"].alignment = Alignment(horizontal="center", vertical="center")
|
| 279 |
+
|
| 280 |
+
ws.merge_cells("E94:G94")
|
| 281 |
+
ws["E94"] = f"์ง๊ธ์ด์: {current_interest}"
|
| 282 |
+
ws["E94"].alignment = Alignment(horizontal="center", vertical="center")
|
| 283 |
+
|
| 284 |
+
ws.merge_cells("E95:G95")
|
| 285 |
+
ws["E95"] = f"๊ธฐํ๋น์ฉ: {other_cost}"
|
| 286 |
+
ws["E95"].alignment = Alignment(horizontal="center", vertical="center")
|
| 287 |
+
|
| 288 |
+
ws.merge_cells("E96:G96")
|
| 289 |
+
ws["E96"] = f"์์ด์ต์จ: {parsed['์์ด์ต์จ']}"
|
| 290 |
+
ws["E96"].alignment = Alignment(horizontal="center", vertical="center")
|
| 291 |
+
|
| 292 |
+
ws.merge_cells("E97:G97")
|
| 293 |
+
ws["E97"] = f"์์์ต: {parsed['์์์์ต']}"
|
| 294 |
+
ws["E97"].alignment = Alignment(horizontal="center", vertical="center")
|
| 295 |
+
|
| 296 |
+
ws.merge_cells("E98:G98")
|
| 297 |
+
ws["E98"] = f"์์ต๋ถ๊ธฐ์ : {parsed['์์ต๋ถ๊ธฐ์ ']}"
|
| 298 |
+
ws["E98"].alignment = Alignment(horizontal="center", vertical="center")
|
| 299 |
+
|
| 300 |
+
# ์ ์ฅ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
output = BytesIO()
|
| 302 |
wb.save(output)
|
| 303 |
output.seek(0)
|
| 304 |
+
|
| 305 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 306 |
tmp.write(output.getvalue())
|
| 307 |
tmp.flush()
|
| 308 |
temp_file_path = tmp.name
|
| 309 |
+
|
| 310 |
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 311 |
os.rename(temp_file_path, final_path)
|
| 312 |
return final_path
|
|
|
|
| 333 |
)
|
| 334 |
|
| 335 |
############################
|
| 336 |
+
# (7) ์์
์์ฑ ํจ์ (์๋จ 8๊ฐ, ์ ๋ก์ฌํญ/๋ชฉํ, ์ฌ์ง)
|
|
|
|
| 337 |
############################
|
|
|
|
| 338 |
def generate_excel(
|
| 339 |
consulting_company_rep,
|
| 340 |
consulting_address,
|
|
|
|
| 352 |
wb = load_workbook("EXE.xlsx")
|
| 353 |
ws = wb.active
|
| 354 |
|
|
|
|
| 355 |
ws.merge_cells("C4:E4")
|
| 356 |
ws["C4"] = consulting_company_rep
|
| 357 |
ws["C4"].alignment = Alignment(horizontal="center", vertical="center")
|
|
|
|
| 384 |
ws["G7"] = consulting_region
|
| 385 |
ws["G7"].alignment = Alignment(horizontal="center", vertical="center")
|
| 386 |
|
|
|
|
| 387 |
ws["D11"] = preview_difficulties
|
| 388 |
ws["D22"] = preview_goals
|
| 389 |
ws["D11"].alignment = Alignment(wrap_text=True)
|
| 390 |
ws["D22"].alignment = Alignment(wrap_text=True)
|
| 391 |
|
|
|
|
| 392 |
width_px = int(37.79 * 5)
|
| 393 |
height_px = int(37.79 * 5)
|
| 394 |
|
|
|
|
| 413 |
output = BytesIO()
|
| 414 |
wb.save(output)
|
| 415 |
output.seek(0)
|
| 416 |
+
|
| 417 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 418 |
tmp.write(output.getvalue())
|
| 419 |
tmp.flush()
|
| 420 |
temp_file_path = tmp.name
|
| 421 |
+
|
| 422 |
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 423 |
os.rename(temp_file_path, final_path)
|
| 424 |
return final_path
|
|
|
|
| 455 |
)
|
| 456 |
|
| 457 |
############################
|
| 458 |
+
# Gradio UI (ํ ํ์ด์ง)
|
| 459 |
############################
|
| 460 |
def main():
|
| 461 |
with gr.Blocks() as demo:
|
| 462 |
+
gr.Markdown("## (๋จ์ผ ํ์ด์ง) ๊ธฐ์กด ์ฝ๋ + ์ฌ๋ฌด๋ถ์ ๊ฒฐ๊ณผ E87:F87:G87 ๋ฑ์ผ๋ก ์ถ๋ ฅ")
|
| 463 |
|
| 464 |
+
# ์๋จ 8๊ฐ
|
| 465 |
+
gr.Markdown("### ์๋จ 8๊ฐ ์ ๋ณด")
|
| 466 |
with gr.Row():
|
| 467 |
consulting_company_rep = gr.Textbox(label="์ปจ์คํ
์
์ฒด๋ช
๋ฐ ๋ํ")
|
| 468 |
consulting_address = gr.Textbox(label="์ปจ์คํ
์ฃผ์")
|
|
|
|
| 477 |
|
| 478 |
gr.Markdown("---")
|
| 479 |
|
| 480 |
+
# ์ ๋ก์ฌํญ/๋ชฉํ
|
| 481 |
+
gr.Markdown("### ์ ๋ก์ฌํญ & ์ปจ์คํ
๋ชฉํ (GPT)")
|
| 482 |
with gr.Row():
|
| 483 |
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 484 |
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
|
|
|
| 485 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 486 |
preview_difficulties_output = gr.Textbox(label="์ ๋ก์ฌํญ ๋ถ์ ๊ฒฐ๊ณผ", lines=3)
|
| 487 |
preview_goals_output = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ๋ถ์ ๊ฒฐ๊ณผ", lines=3)
|
| 488 |
|
| 489 |
analyze_button.click(
|
| 490 |
+
fn=analyze_texts,
|
| 491 |
inputs=[difficulties_input, goals_input],
|
| 492 |
outputs=[preview_difficulties_output, preview_goals_output]
|
| 493 |
)
|
| 494 |
|
| 495 |
gr.Markdown("---")
|
| 496 |
|
| 497 |
+
# ์ฌ์ง
|
| 498 |
+
gr.Markdown("### ์ฌ์ง (B117/F117, 5ร5cm)")
|
| 499 |
with gr.Row():
|
| 500 |
photo_input_1 = gr.Image(label="์์ง์
์ฒด์ฌ์ง1", type="pil")
|
| 501 |
photo_input_2 = gr.Image(label="์์ง์
์ฒด์ฌ์ง2", type="pil")
|
| 502 |
|
| 503 |
gr.Markdown("---")
|
| 504 |
|
| 505 |
+
# SWOT
|
| 506 |
+
gr.Markdown("### SWOT ๋ถ์")
|
| 507 |
strengths_input = gr.Textbox(label="๊ฐ์ ")
|
| 508 |
weaknesses_input = gr.Textbox(label="์ฝ์ ")
|
| 509 |
opportunities_input = gr.Textbox(label="๊ธฐํ")
|
|
|
|
| 517 |
outputs=swot_result_output
|
| 518 |
)
|
| 519 |
|
| 520 |
+
swot_excel_button = gr.Button("SWOT ๊ฒฐ๊ณผ EXE.xlsx")
|
|
|
|
| 521 |
swot_excel_file = gr.File(label="SWOT_EXCEL ๋ค์ด๋ก๋")
|
| 522 |
swot_excel_button.click(
|
| 523 |
fn=run_export_swot_excel,
|
|
|
|
| 527 |
|
| 528 |
gr.Markdown("---")
|
| 529 |
|
| 530 |
+
# ์ฌ๋ฌด๋ถ์ -> ์์
(ํ๋ฉด ํ์X)
|
| 531 |
+
gr.Markdown("### ์ฌ๋ฌด๋ถ์ -> (E87:F87:G87.. E98:F98:G98) ์์
์๋ง ๊ธฐ๋ก")
|
| 532 |
with gr.Row():
|
| 533 |
avg_monthly_sales_input = gr.Textbox(label="์ํ๊ท ๋งค์ถ์ก")
|
| 534 |
+
rent_input = gr.Textbox(label="์์ฐจ๋ฃ")
|
| 535 |
labor_cost_input = gr.Textbox(label="์ธ๊ฑด๋น")
|
| 536 |
+
management_cost_input = gr.Textbox(label="๊ด๋ฆฌ๋น")
|
|
|
|
| 537 |
|
| 538 |
with gr.Row():
|
| 539 |
+
utilities_input = gr.Textbox(label="์๋๊ด์ด๋น")
|
| 540 |
+
current_interest_input = gr.Textbox(label="์ง๊ธ์ด์")
|
|
|
|
| 541 |
other_cost_input = gr.Textbox(label="๊ธฐํ๋น์ฉ")
|
| 542 |
+
cost_ratio_input = gr.Textbox(label="์๊ฐ์จ")
|
| 543 |
|
| 544 |
+
fin_excel_button = gr.Button("์ฌ๋ฌด๋ถ์ Excel ๋ค์ด๋ก๋")
|
| 545 |
+
fin_excel_file = gr.File(label="์ฌ๋ฌด๋ถ์_EXCEL")
|
| 546 |
+
fin_excel_button.click(
|
|
|
|
|
|
|
| 547 |
fn=run_generate_financial_excel,
|
| 548 |
inputs=[
|
| 549 |
avg_monthly_sales_input,
|
|
|
|
| 555 |
other_cost_input,
|
| 556 |
cost_ratio_input
|
| 557 |
],
|
| 558 |
+
outputs=[fin_excel_file]
|
| 559 |
)
|
| 560 |
|
| 561 |
gr.Markdown("---")
|
| 562 |
|
| 563 |
+
# ์๊ถ๋ถ์
|
| 564 |
+
gr.Markdown("### ์๊ถ๋ถ์ (6์ค ์ด๋ด)")
|
| 565 |
region_input = gr.Textbox(label="์ง์ญ")
|
| 566 |
industry_input = gr.Textbox(label="์
์ข
")
|
| 567 |
+
result_output_market = gr.Textbox(label="์๊ถ๋ถ์ ๊ฒฐ๊ณผ(์ต๋ 6์ค)")
|
| 568 |
+
analyze_button_market = gr.Button("๋ถ์ํ๊ธฐ")
|
|
|
|
|
|
|
| 569 |
analyze_button_market.click(
|
| 570 |
+
fn=analyze_market,
|
| 571 |
inputs=[region_input, industry_input],
|
| 572 |
outputs=result_output_market
|
| 573 |
)
|
| 574 |
|
| 575 |
gr.Markdown("---")
|
| 576 |
|
| 577 |
+
# ์ต์ข
(์๋จ8 + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง)
|
| 578 |
+
gr.Markdown("### ์๋จ8 + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง โ EXE.xlsx")
|
| 579 |
+
final_excel_button = gr.Button("์ต์ข
Excel ๋ค์ด๋ก๋")
|
| 580 |
+
final_excel_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญํ์ ์ฅ)")
|
|
|
|
| 581 |
final_excel_button.click(
|
| 582 |
fn=run_generate_excel,
|
| 583 |
inputs=[
|
|
|
|
| 584 |
consulting_company_rep,
|
| 585 |
consulting_address,
|
| 586 |
consulting_field,
|
|
|
|
| 589 |
consulting_date_time,
|
| 590 |
consulting_round,
|
| 591 |
consulting_region,
|
|
|
|
|
|
|
| 592 |
photo_input_1,
|
| 593 |
photo_input_2,
|
|
|
|
|
|
|
| 594 |
difficulties_input,
|
| 595 |
goals_input,
|
| 596 |
preview_difficulties_output,
|