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},
|
|
@@ -32,6 +32,9 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
|
|
| 32 |
# (1) ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์ ํจ์
|
| 33 |
############################
|
| 34 |
def analyze_texts(difficulties, goals):
|
|
|
|
|
|
|
|
|
|
| 35 |
preview_difficulties = call_api(
|
| 36 |
content=difficulties,
|
| 37 |
system_message=(
|
|
@@ -72,6 +75,9 @@ def analyze_financials(
|
|
| 72 |
other_cost,
|
| 73 |
cost_ratio
|
| 74 |
):
|
|
|
|
|
|
|
|
|
|
| 75 |
system_message = (
|
| 76 |
"๋น์ ์ ์ธ๋ฌด์ฌ(ํ๊ณ์ฌ)์
๋๋ค. ์๋ ์
๋ ฅ๊ฐ์ ๋ฐํ์ผ๋ก ๊ณ์ฐํ ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, "
|
| 77 |
"์์์์ต, ์์ต๋ถ๊ธฐ์ ์ '์ ๋ชฉ: ์์น' ํ์์ผ๋ก๋ง ์๋ ค์ฃผ์ธ์. "
|
|
@@ -125,6 +131,9 @@ def analyze_swot(strengths, weaknesses, opportunities, threats):
|
|
| 125 |
# (4) ์๊ถ ๋ถ์ ํจ์ (6์ค ์ด๋ด)
|
| 126 |
############################
|
| 127 |
def analyze_market(region, industry):
|
|
|
|
|
|
|
|
|
|
| 128 |
system_message = (
|
| 129 |
"๋น์ ์ ์๊ถ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์
๋ ฅ๋ ์ง์ญ๊ณผ ์
์ข
์ ๋ํด 1km ์ด๋ด ์๊ถ์ ๋ถ์ํด ์ฃผ์ธ์. "
|
| 130 |
"์ฌ์ง(๋๋ ์๊ฐ์๋ฃ)์ ๋ํ ์ธ๊ธ ํฌํจ, ์๋ต์ 6์ค ์ด๋ด๋ก ์ ํํ์ธ์."
|
|
@@ -142,7 +151,7 @@ def analyze_market(region, industry):
|
|
| 142 |
)
|
| 143 |
|
| 144 |
############################
|
| 145 |
-
# (5) SWOT ๊ฒฐ๊ณผ
|
| 146 |
############################
|
| 147 |
def export_swot_excel(strengths, weaknesses, opportunities, threats):
|
| 148 |
wb = load_workbook("EXE.xlsx")
|
|
@@ -318,14 +327,14 @@ def run_generate_financial_excel(
|
|
| 318 |
other_cost,
|
| 319 |
cost_ratio
|
| 320 |
):
|
| 321 |
-
#
|
| 322 |
pass
|
| 323 |
|
| 324 |
############################
|
| 325 |
# (8) ์๊ถ๋ถ์ -> EXE.xlsx (ํ๋ฉด ํ์X)
|
| 326 |
############################
|
| 327 |
def run_export_market_excel(region, industry):
|
| 328 |
-
#
|
| 329 |
pass
|
| 330 |
|
| 331 |
############################
|
|
@@ -333,10 +342,9 @@ def run_export_market_excel(region, industry):
|
|
| 333 |
############################
|
| 334 |
def main():
|
| 335 |
with gr.Blocks() as demo:
|
| 336 |
-
gr.Markdown("## (๋จ์ผ ํ์ด์ง)
|
| 337 |
|
| 338 |
# ์๋จ 8๊ฐ ์ ๋ณด
|
| 339 |
-
gr.Markdown("### ์๋จ 8๊ฐ ์ ๋ณด (C4:E4.. G7:H7)")
|
| 340 |
with gr.Row():
|
| 341 |
consulting_company_rep = gr.Textbox(label="์ปจ์คํ
์
์ฒด๋ช
๋ฐ ๋ํ")
|
| 342 |
consulting_address = gr.Textbox(label="์ปจ์คํ
์ฃผ์")
|
|
@@ -351,26 +359,25 @@ def main():
|
|
| 351 |
|
| 352 |
gr.Markdown("---")
|
| 353 |
|
| 354 |
-
# ์ ๋ก์ฌํญ/๋ชฉํ
|
| 355 |
-
gr.
|
| 356 |
-
|
| 357 |
-
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 358 |
-
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
| 359 |
-
|
| 360 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 361 |
-
preview_difficulties_output = gr.Textbox(label="์ ๋ก์ฌํญ ๋ถ์ ๊ฒฐ๊ณผ", lines=3)
|
| 362 |
-
preview_goals_output = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ๋ถ์ ๊ฒฐ๊ณผ", lines=3)
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
analyze_button.click(
|
| 365 |
fn=analyze_texts,
|
| 366 |
inputs=[difficulties_input, goals_input],
|
| 367 |
-
outputs=[
|
| 368 |
)
|
| 369 |
|
| 370 |
gr.Markdown("---")
|
| 371 |
|
| 372 |
# ์ฌ์ง
|
| 373 |
-
gr.Markdown("### ์ฌ์ง ์
๋ก๋ (B117/F117, 5ร5cm)")
|
| 374 |
with gr.Row():
|
| 375 |
photo_input_1 = gr.Image(label="์์ง์
์ฒด์ฌ์ง1", type="pil")
|
| 376 |
photo_input_2 = gr.Image(label="์์ง์
์ฒด์ฌ์ง2", type="pil")
|
|
@@ -378,23 +385,21 @@ def main():
|
|
| 378 |
gr.Markdown("---")
|
| 379 |
|
| 380 |
# SWOT
|
| 381 |
-
gr.Markdown("### SWOT ๋ถ์ - ๊ฒฐ๊ณผ๋ ํ๋ฉด ๋ฏธํ์, Excel๋ง")
|
| 382 |
strengths_input = gr.Textbox(label="๊ฐ์ ")
|
| 383 |
weaknesses_input = gr.Textbox(label="์ฝ์ ")
|
| 384 |
opportunities_input = gr.Textbox(label="๊ธฐํ")
|
| 385 |
threats_input = gr.Textbox(label="์ํ")
|
| 386 |
|
| 387 |
swot_button = gr.Button("SWOT ๋ถ์ํ๊ธฐ")
|
| 388 |
-
# ํ๋ฉด ์ถ๋ ฅ ์์ด -> State์๋ง ์ ์ฅ
|
| 389 |
-
swot_result_state = gr.State()
|
| 390 |
|
|
|
|
|
|
|
| 391 |
swot_button.click(
|
| 392 |
fn=analyze_swot,
|
| 393 |
inputs=[strengths_input, weaknesses_input, opportunities_input, threats_input],
|
| 394 |
outputs=[swot_result_state]
|
| 395 |
)
|
| 396 |
|
| 397 |
-
# Excel ๋ค์ด๋ก๋
|
| 398 |
swot_excel_button = gr.Button("SWOT ๊ฒฐ๊ณผ EXE.xlsx")
|
| 399 |
swot_excel_file = gr.File(label="SWOT_EXCEL ๋ค์ด๋ก๋")
|
| 400 |
swot_excel_button.click(
|
|
@@ -405,8 +410,7 @@ def main():
|
|
| 405 |
|
| 406 |
gr.Markdown("---")
|
| 407 |
|
| 408 |
-
# ์ฌ๋ฌด๋ถ์
|
| 409 |
-
gr.Markdown("### ์ฌ๋ฌด๋ถ์ (๊ฒฐ๊ณผ(์ ๋ชฉ: ์์น) ํ๋ฉด ํ์)")
|
| 410 |
with gr.Row():
|
| 411 |
avg_monthly_sales_input = gr.Textbox(label="์ํ๊ท ๋งค์ถ์ก")
|
| 412 |
rent_input = gr.Textbox(label="์์ฐจ๋ฃ")
|
|
@@ -419,11 +423,10 @@ def main():
|
|
| 419 |
other_cost_input = gr.Textbox(label="๊ธฐํ๋น์ฉ")
|
| 420 |
cost_ratio_input = gr.Textbox(label="์๊ฐ์จ")
|
| 421 |
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
fn=analyze_financials,
|
| 427 |
inputs=[
|
| 428 |
avg_monthly_sales_input,
|
| 429 |
rent_input,
|
|
@@ -434,29 +437,26 @@ def main():
|
|
| 434 |
other_cost_input,
|
| 435 |
cost_ratio_input
|
| 436 |
],
|
| 437 |
-
outputs=
|
| 438 |
)
|
| 439 |
|
| 440 |
gr.Markdown("---")
|
| 441 |
|
| 442 |
-
# ์๊ถ๋ถ์
|
| 443 |
-
gr.Markdown("### ์๊ถ๋ถ์ (6์ค ์ด๋ด, ํ๋ฉด ํ์)")
|
| 444 |
region_input = gr.Textbox(label="์ง์ญ")
|
| 445 |
industry_input = gr.Textbox(label="์
์ข
")
|
| 446 |
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
fn=analyze_market,
|
| 452 |
inputs=[region_input, industry_input],
|
| 453 |
-
outputs=
|
| 454 |
)
|
| 455 |
|
| 456 |
gr.Markdown("---")
|
| 457 |
|
| 458 |
-
# ์ต์ข
Excel
|
| 459 |
-
gr.Markdown("### ์๋จ8๊ฐ + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง โ EXE.xlsx")
|
| 460 |
final_excel_button = gr.Button("์ต์ข
EXE.xlsx ๋ค์ด๋ก๋")
|
| 461 |
final_excel_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญ ํ ์ ์ฅ)")
|
| 462 |
|
|
@@ -475,8 +475,9 @@ def main():
|
|
| 475 |
photo_input_2,
|
| 476 |
difficulties_input,
|
| 477 |
goals_input,
|
| 478 |
-
|
| 479 |
-
|
|
|
|
| 480 |
],
|
| 481 |
outputs=[final_excel_file]
|
| 482 |
)
|
|
|
|
| 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 |
# (1) ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์ ํจ์
|
| 33 |
############################
|
| 34 |
def analyze_texts(difficulties, goals):
|
| 35 |
+
"""
|
| 36 |
+
์ ๋ก์ฌํญ / ์ปจ์คํ
๋ชฉํ๋ฅผ gpt-4o-mini๋ก ๋ถ์ (์ต์ 4์ค ์ด์, '~์ต๋๋ค.'๋ก ๋ง๋ฌด๋ฆฌ)
|
| 37 |
+
"""
|
| 38 |
preview_difficulties = call_api(
|
| 39 |
content=difficulties,
|
| 40 |
system_message=(
|
|
|
|
| 75 |
other_cost,
|
| 76 |
cost_ratio
|
| 77 |
):
|
| 78 |
+
"""
|
| 79 |
+
GPT๋ก ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, ์์์์ต, ์์ต๋ถ๊ธฐ์ โ '์ ๋ชฉ: ์์น' ํํ ๋ฐํ
|
| 80 |
+
"""
|
| 81 |
system_message = (
|
| 82 |
"๋น์ ์ ์ธ๋ฌด์ฌ(ํ๊ณ์ฌ)์
๋๋ค. ์๋ ์
๋ ฅ๊ฐ์ ๋ฐํ์ผ๋ก ๊ณ์ฐํ ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, "
|
| 83 |
"์์์์ต, ์์ต๋ถ๊ธฐ์ ์ '์ ๋ชฉ: ์์น' ํ์์ผ๋ก๋ง ์๋ ค์ฃผ์ธ์. "
|
|
|
|
| 131 |
# (4) ์๊ถ ๋ถ์ ํจ์ (6์ค ์ด๋ด)
|
| 132 |
############################
|
| 133 |
def analyze_market(region, industry):
|
| 134 |
+
"""
|
| 135 |
+
์ง์ญ+์
์ข
โ 1km ์ด๋ด ์๊ถ๋ถ์ (์ฌ์ง ์ธ๊ธ, 6์ค ์ด๋ด)
|
| 136 |
+
"""
|
| 137 |
system_message = (
|
| 138 |
"๋น์ ์ ์๊ถ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์
๋ ฅ๋ ์ง์ญ๊ณผ ์
์ข
์ ๋ํด 1km ์ด๋ด ์๊ถ์ ๋ถ์ํด ์ฃผ์ธ์. "
|
| 139 |
"์ฌ์ง(๋๋ ์๊ฐ์๋ฃ)์ ๋ํ ์ธ๊ธ ํฌํจ, ์๋ต์ 6์ค ์ด๋ด๋ก ์ ํํ์ธ์."
|
|
|
|
| 151 |
)
|
| 152 |
|
| 153 |
############################
|
| 154 |
+
# (5) SWOT ๊ฒฐ๊ณผ -> EXE.xlsx
|
| 155 |
############################
|
| 156 |
def export_swot_excel(strengths, weaknesses, opportunities, threats):
|
| 157 |
wb = load_workbook("EXE.xlsx")
|
|
|
|
| 327 |
other_cost,
|
| 328 |
cost_ratio
|
| 329 |
):
|
| 330 |
+
# ์๋ณธ ๋ก์ง
|
| 331 |
pass
|
| 332 |
|
| 333 |
############################
|
| 334 |
# (8) ์๊ถ๋ถ์ -> EXE.xlsx (ํ๋ฉด ํ์X)
|
| 335 |
############################
|
| 336 |
def run_export_market_excel(region, industry):
|
| 337 |
+
# ์๋ณธ ๋ก์ง
|
| 338 |
pass
|
| 339 |
|
| 340 |
############################
|
|
|
|
| 342 |
############################
|
| 343 |
def main():
|
| 344 |
with gr.Blocks() as demo:
|
| 345 |
+
gr.Markdown("## (๋จ์ผ ํ์ด์ง) ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์ ๊ฒฐ๊ณผ๋ ํ๋ฉด ๋ฏธํ์, Excel๋ง")
|
| 346 |
|
| 347 |
# ์๋จ 8๊ฐ ์ ๋ณด
|
|
|
|
| 348 |
with gr.Row():
|
| 349 |
consulting_company_rep = gr.Textbox(label="์ปจ์คํ
์
์ฒด๋ช
๋ฐ ๋ํ")
|
| 350 |
consulting_address = gr.Textbox(label="์ปจ์คํ
์ฃผ์")
|
|
|
|
| 359 |
|
| 360 |
gr.Markdown("---")
|
| 361 |
|
| 362 |
+
# ์ ๋ก์ฌํญ/๋ชฉํ ์
๋ ฅ
|
| 363 |
+
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 364 |
+
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
|
|
|
|
|
|
|
|
|
| 365 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
|
|
|
|
|
|
| 366 |
|
| 367 |
+
# โ
ํ๋ฉด ํ์ํ Textbox ๋์ , State๋ก ๋ด๋ถ ๋ณด๊ด
|
| 368 |
+
preview_difficulties_state = gr.State()
|
| 369 |
+
preview_goals_state = gr.State()
|
| 370 |
+
|
| 371 |
+
# ๋ถ์ํ๊ธฐ -> GPT
|
| 372 |
analyze_button.click(
|
| 373 |
fn=analyze_texts,
|
| 374 |
inputs=[difficulties_input, goals_input],
|
| 375 |
+
outputs=[preview_difficulties_state, preview_goals_state]
|
| 376 |
)
|
| 377 |
|
| 378 |
gr.Markdown("---")
|
| 379 |
|
| 380 |
# ์ฌ์ง
|
|
|
|
| 381 |
with gr.Row():
|
| 382 |
photo_input_1 = gr.Image(label="์์ง์
์ฒด์ฌ์ง1", type="pil")
|
| 383 |
photo_input_2 = gr.Image(label="์์ง์
์ฒด์ฌ์ง2", type="pil")
|
|
|
|
| 385 |
gr.Markdown("---")
|
| 386 |
|
| 387 |
# SWOT
|
|
|
|
| 388 |
strengths_input = gr.Textbox(label="๊ฐ์ ")
|
| 389 |
weaknesses_input = gr.Textbox(label="์ฝ์ ")
|
| 390 |
opportunities_input = gr.Textbox(label="๊ธฐํ")
|
| 391 |
threats_input = gr.Textbox(label="์ํ")
|
| 392 |
|
| 393 |
swot_button = gr.Button("SWOT ๋ถ์ํ๊ธฐ")
|
|
|
|
|
|
|
| 394 |
|
| 395 |
+
# ํ๋ฉด์ ํ์ X
|
| 396 |
+
swot_result_state = gr.State()
|
| 397 |
swot_button.click(
|
| 398 |
fn=analyze_swot,
|
| 399 |
inputs=[strengths_input, weaknesses_input, opportunities_input, threats_input],
|
| 400 |
outputs=[swot_result_state]
|
| 401 |
)
|
| 402 |
|
|
|
|
| 403 |
swot_excel_button = gr.Button("SWOT ๊ฒฐ๊ณผ EXE.xlsx")
|
| 404 |
swot_excel_file = gr.File(label="SWOT_EXCEL ๋ค์ด๋ก๋")
|
| 405 |
swot_excel_button.click(
|
|
|
|
| 410 |
|
| 411 |
gr.Markdown("---")
|
| 412 |
|
| 413 |
+
# ์ฌ๋ฌด๋ถ์ (ํ๋ฉด ํ์ X)
|
|
|
|
| 414 |
with gr.Row():
|
| 415 |
avg_monthly_sales_input = gr.Textbox(label="์ํ๊ท ๋งค์ถ์ก")
|
| 416 |
rent_input = gr.Textbox(label="์์ฐจ๋ฃ")
|
|
|
|
| 423 |
other_cost_input = gr.Textbox(label="๊ธฐํ๋น์ฉ")
|
| 424 |
cost_ratio_input = gr.Textbox(label="์๊ฐ์จ")
|
| 425 |
|
| 426 |
+
fin_excel_button = gr.Button("์ฌ๋ฌด๋ถ์ Excel ๋ค์ด๋ก๋")
|
| 427 |
+
fin_excel_file = gr.File(label="์ฌ๋ฌด๋ถ์_EXCEL")
|
| 428 |
+
fin_excel_button.click(
|
| 429 |
+
fn=run_generate_financial_excel,
|
|
|
|
| 430 |
inputs=[
|
| 431 |
avg_monthly_sales_input,
|
| 432 |
rent_input,
|
|
|
|
| 437 |
other_cost_input,
|
| 438 |
cost_ratio_input
|
| 439 |
],
|
| 440 |
+
outputs=[fin_excel_file]
|
| 441 |
)
|
| 442 |
|
| 443 |
gr.Markdown("---")
|
| 444 |
|
| 445 |
+
# ์๊ถ๋ถ์
|
|
|
|
| 446 |
region_input = gr.Textbox(label="์ง์ญ")
|
| 447 |
industry_input = gr.Textbox(label="์
์ข
")
|
| 448 |
|
| 449 |
+
market_excel_button = gr.Button("์๊ถ๋ถ์ Excel ๋ค์ด๋ก๋")
|
| 450 |
+
market_excel_file = gr.File(label="์๊ถ๋ถ์_EXCEL")
|
| 451 |
+
market_excel_button.click(
|
| 452 |
+
fn=run_export_market_excel,
|
|
|
|
| 453 |
inputs=[region_input, industry_input],
|
| 454 |
+
outputs=[market_excel_file]
|
| 455 |
)
|
| 456 |
|
| 457 |
gr.Markdown("---")
|
| 458 |
|
| 459 |
+
# ์ต์ข
(์๋จ8 + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง) Excel
|
|
|
|
| 460 |
final_excel_button = gr.Button("์ต์ข
EXE.xlsx ๋ค์ด๋ก๋")
|
| 461 |
final_excel_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญ ํ ์ ์ฅ)")
|
| 462 |
|
|
|
|
| 475 |
photo_input_2,
|
| 476 |
difficulties_input,
|
| 477 |
goals_input,
|
| 478 |
+
# GPT ๋ถ์ ๊ฒฐ๊ณผ (State)
|
| 479 |
+
preview_difficulties_state,
|
| 480 |
+
preview_goals_state
|
| 481 |
],
|
| 482 |
outputs=[final_excel_file]
|
| 483 |
)
|