Sangwon78 commited on
Commit
84ea695
ยท
verified ยท
1 Parent(s): f836a49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -40
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 ๊ฒฐ๊ณผ๋ฅผ EXE.xlsx์— ๊ธฐ์žฌ
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("## (๋‹จ์ผ ํŽ˜์ด์ง€) ์ด์ „ ์ƒํƒœ + SWOT ๋ถ„์„ ๊ฒฐ๊ณผ ํ™”๋ฉด ๋ฏธํ‘œ์‹œ")
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
- # ์• ๋กœ์‚ฌํ•ญ/๋ชฉํ‘œ -> GPT
355
- gr.Markdown("### ์• ๋กœ์‚ฌํ•ญ & ์ปจ์„คํŒ… ๋ชฉํ‘œ (ํ™”๋ฉด์— ํ‘œ์‹œ)")
356
- with gr.Row():
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=[preview_difficulties_output, preview_goals_output]
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
- result_output_fin = gr.Textbox(label="๊ฒฐ๊ณผ(์ œ๋ชฉ: ์ˆ˜์น˜)")
423
- analyze_button_fin = gr.Button("๊ณ„์‚ฐํ•˜๊ธฐ")
424
-
425
- analyze_button_fin.click(
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=result_output_fin
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
- result_output_market = gr.Textbox(label="์ƒ๊ถŒ๋ถ„์„ ๊ฒฐ๊ณผ (์ตœ๋Œ€ 6์ค„)")
448
- analyze_button_market = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
449
-
450
- analyze_button_market.click(
451
- fn=analyze_market,
452
  inputs=[region_input, industry_input],
453
- outputs=result_output_market
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
- preview_difficulties_output,
479
- preview_goals_output
 
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
  )