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},
|
|
@@ -29,12 +29,9 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
|
|
| 29 |
return response.choices[0].message["content"]
|
| 30 |
|
| 31 |
############################
|
| 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=(
|
|
@@ -62,7 +59,7 @@ def analyze_texts(difficulties, goals):
|
|
| 62 |
return preview_difficulties, preview_goals
|
| 63 |
|
| 64 |
############################
|
| 65 |
-
# (2) ์ฌ๋ฌด ๋ถ์ ํจ์
|
| 66 |
############################
|
| 67 |
def analyze_financials(
|
| 68 |
avg_monthly_sales,
|
|
@@ -74,9 +71,6 @@ def analyze_financials(
|
|
| 74 |
other_cost,
|
| 75 |
cost_ratio
|
| 76 |
):
|
| 77 |
-
"""
|
| 78 |
-
์ฌ๋ฌด๋ถ์: GPT๋ก ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, ์์์์ต, ์์ต๋ถ๊ธฐ์ ๊ณ์ฐ
|
| 79 |
-
"""
|
| 80 |
system_message = (
|
| 81 |
"๋น์ ์ ์ธ๋ฌด์ฌ(ํ๊ณ์ฌ)์
๋๋ค. ์๋ ์
๋ ฅ๊ฐ์ ๋ฐํ์ผ๋ก ๊ณ์ฐํ ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, "
|
| 82 |
"์์์์ต, ์์ต๋ถ๊ธฐ์ ์ '์ ๋ชฉ: ์์น' ํ์์ผ๋ก๋ง ์๋ ค์ฃผ์ธ์. "
|
|
@@ -108,12 +102,9 @@ def analyze_financials(
|
|
| 108 |
)
|
| 109 |
|
| 110 |
############################
|
| 111 |
-
# (3) SWOT ๋ถ์ ํจ์
|
| 112 |
############################
|
| 113 |
def analyze_swot(strengths, weaknesses, opportunities, threats):
|
| 114 |
-
"""
|
| 115 |
-
SWOT -> gpt-4o-mini
|
| 116 |
-
"""
|
| 117 |
system_message = "๋น์ ์ swot ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ์ฉ์์ ๊ฐ์ , ์ฝ์ , ๊ธฐํ, ์ํ์ ๋ํด ๊ฒ์ํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๊ณตํฉ๋๋ค."
|
| 118 |
content = f"""
|
| 119 |
๊ฐ์ : {strengths}
|
|
@@ -130,12 +121,9 @@ def analyze_swot(strengths, weaknesses, opportunities, threats):
|
|
| 130 |
)
|
| 131 |
|
| 132 |
############################
|
| 133 |
-
# (4) ์๊ถ ๋ถ์ ํจ์
|
| 134 |
############################
|
| 135 |
def analyze_market(region, industry):
|
| 136 |
-
"""
|
| 137 |
-
์๊ถ๋ถ์ -> gpt-4o-mini (6์ค ์ด๋ด)
|
| 138 |
-
"""
|
| 139 |
system_message = (
|
| 140 |
"๋น์ ์ ์๊ถ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์
๋ ฅ๋ ์ง์ญ๊ณผ ์
์ข
์ ๋ํด 1km ์ด๋ด ์๊ถ์ ๋ถ์ํด ์ฃผ์ธ์. "
|
| 141 |
"์ฌ์ง(๋๋ ์๊ฐ์๋ฃ)์ ๋ํ ์ธ๊ธ ํฌํจ, ์๋ต์ 6์ค ์ด๋ด๋ก ์ ํํ์ธ์."
|
|
@@ -153,34 +141,241 @@ def analyze_market(region, industry):
|
|
| 153 |
)
|
| 154 |
|
| 155 |
############################
|
| 156 |
-
# (5)
|
| 157 |
-
# (์ด
|
| 158 |
############################
|
| 159 |
|
| 160 |
def export_swot_excel(strengths, weaknesses, opportunities, threats):
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
############################
|
| 173 |
-
# (โ
) ์ต์ข
ํ๋์
|
| 174 |
############################
|
| 175 |
-
def run_all_in_one(
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
############################
|
| 179 |
# Gradio UI
|
| 180 |
############################
|
| 181 |
def main():
|
| 182 |
with gr.Blocks() as demo:
|
| 183 |
-
gr.Markdown("## (๋จ์ผ ํ์ด์ง)
|
| 184 |
|
| 185 |
# [1] ์๋จ 8๊ฐ
|
| 186 |
with gr.Row():
|
|
@@ -200,16 +395,14 @@ def main():
|
|
| 200 |
# [2] ์ ๋ก์ฌํญ/๋ชฉํ
|
| 201 |
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 202 |
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
| 203 |
-
|
| 204 |
-
#
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
preview_goals_output = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ๋ถ์ ๊ฒฐ๊ณผ", lines=3)
|
| 208 |
-
|
| 209 |
analyze_button.click(
|
| 210 |
fn=analyze_texts,
|
| 211 |
inputs=[difficulties_input, goals_input],
|
| 212 |
-
outputs=[
|
| 213 |
)
|
| 214 |
|
| 215 |
gr.Markdown("---")
|
|
@@ -227,13 +420,13 @@ def main():
|
|
| 227 |
opportunities_input = gr.Textbox(label="๊ธฐํ")
|
| 228 |
threats_input = gr.Textbox(label="์ํ")
|
| 229 |
|
| 230 |
-
#
|
| 231 |
swot_button = gr.Button("SWOT ๋ถ์ํ๊ธฐ")
|
| 232 |
-
|
| 233 |
swot_button.click(
|
| 234 |
fn=analyze_swot,
|
| 235 |
inputs=[strengths_input, weaknesses_input, opportunities_input, threats_input],
|
| 236 |
-
outputs=
|
| 237 |
)
|
| 238 |
|
| 239 |
gr.Markdown("---")
|
|
@@ -251,15 +444,16 @@ def main():
|
|
| 251 |
other_cost_input = gr.Textbox(label="๊ธฐํ๋น์ฉ")
|
| 252 |
cost_ratio_input = gr.Textbox(label="์๊ฐ์จ")
|
| 253 |
|
| 254 |
-
#
|
|
|
|
| 255 |
|
| 256 |
gr.Markdown("---")
|
| 257 |
|
| 258 |
# [6] ์๊ถ๋ถ์
|
| 259 |
region_input = gr.Textbox(label="์ง์ญ")
|
| 260 |
industry_input = gr.Textbox(label="์
์ข
")
|
| 261 |
-
|
| 262 |
-
# (
|
| 263 |
|
| 264 |
gr.Markdown("---")
|
| 265 |
|
|
@@ -267,6 +461,7 @@ def main():
|
|
| 267 |
all_in_one_button = gr.Button("๋ชจ๋ ์
๋ ฅ ํ, Excel ๋ค์ด๋ก๋")
|
| 268 |
all_in_one_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญ ํ ์ ์ฅ)")
|
| 269 |
|
|
|
|
| 270 |
all_in_one_button.click(
|
| 271 |
fn=run_all_in_one,
|
| 272 |
inputs=[
|
|
@@ -303,8 +498,8 @@ def main():
|
|
| 303 |
photo_input_2,
|
| 304 |
difficulties_input,
|
| 305 |
goals_input,
|
| 306 |
-
|
| 307 |
-
|
| 308 |
],
|
| 309 |
outputs=[all_in_one_file]
|
| 310 |
)
|
|
|
|
| 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},
|
|
|
|
| 29 |
return response.choices[0].message["content"]
|
| 30 |
|
| 31 |
############################
|
| 32 |
+
# (1) ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์ ํจ์ (๊ธฐ์กด)
|
| 33 |
############################
|
| 34 |
def analyze_texts(difficulties, goals):
|
|
|
|
|
|
|
|
|
|
| 35 |
preview_difficulties = call_api(
|
| 36 |
content=difficulties,
|
| 37 |
system_message=(
|
|
|
|
| 59 |
return preview_difficulties, preview_goals
|
| 60 |
|
| 61 |
############################
|
| 62 |
+
# (2) ์ฌ๋ฌด ๋ถ์ ํจ์ (๊ธฐ์กด)
|
| 63 |
############################
|
| 64 |
def analyze_financials(
|
| 65 |
avg_monthly_sales,
|
|
|
|
| 71 |
other_cost,
|
| 72 |
cost_ratio
|
| 73 |
):
|
|
|
|
|
|
|
|
|
|
| 74 |
system_message = (
|
| 75 |
"๋น์ ์ ์ธ๋ฌด์ฌ(ํ๊ณ์ฌ)์
๋๋ค. ์๋ ์
๋ ฅ๊ฐ์ ๋ฐํ์ผ๋ก ๊ณ์ฐํ ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ, "
|
| 76 |
"์์์์ต, ์์ต๋ถ๊ธฐ์ ์ '์ ๋ชฉ: ์์น' ํ์์ผ๋ก๋ง ์๋ ค์ฃผ์ธ์. "
|
|
|
|
| 102 |
)
|
| 103 |
|
| 104 |
############################
|
| 105 |
+
# (3) SWOT ๋ถ์ ํจ์ (๊ธฐ์กด)
|
| 106 |
############################
|
| 107 |
def analyze_swot(strengths, weaknesses, opportunities, threats):
|
|
|
|
|
|
|
|
|
|
| 108 |
system_message = "๋น์ ์ swot ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ์ฉ์์ ๊ฐ์ , ์ฝ์ , ๊ธฐํ, ์ํ์ ๋ํด ๊ฒ์ํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๊ณตํฉ๋๋ค."
|
| 109 |
content = f"""
|
| 110 |
๊ฐ์ : {strengths}
|
|
|
|
| 121 |
)
|
| 122 |
|
| 123 |
############################
|
| 124 |
+
# (4) ์๊ถ ๋ถ์ ํจ์ (๊ธฐ์กด)
|
| 125 |
############################
|
| 126 |
def analyze_market(region, industry):
|
|
|
|
|
|
|
|
|
|
| 127 |
system_message = (
|
| 128 |
"๋น์ ์ ์๊ถ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค. ์
๋ ฅ๋ ์ง์ญ๊ณผ ์
์ข
์ ๋ํด 1km ์ด๋ด ์๊ถ์ ๋ถ์ํด ์ฃผ์ธ์. "
|
| 129 |
"์ฌ์ง(๋๋ ์๊ฐ์๋ฃ)์ ๋ํ ์ธ๊ธ ํฌํจ, ์๋ต์ 6์ค ์ด๋ด๋ก ์ ํํ์ธ์."
|
|
|
|
| 141 |
)
|
| 142 |
|
| 143 |
############################
|
| 144 |
+
# (5) ํจ์๋ค: SWOT->EXE, ์ฌ๋ฌด->EXE, ์๊ถ->EXE, ์ ๋ก์ฌํญ->EXE
|
| 145 |
+
# (๊ธฐ์กด์ ๊ฐ๊ฐ ๋ฒํผ์ด ์์์ผ๋, ์ฌ๊ธฐ์๋ ํ๋๋ก ํฉ์น ์์ )
|
| 146 |
############################
|
| 147 |
|
| 148 |
def export_swot_excel(strengths, weaknesses, opportunities, threats):
|
| 149 |
+
"""
|
| 150 |
+
๊ธฐ์กด run_export_swot_excel() ๋ด์ฉ
|
| 151 |
+
"""
|
| 152 |
+
wb = load_workbook("EXE.xlsx")
|
| 153 |
+
ws = wb.active
|
| 154 |
+
|
| 155 |
+
ws.merge_cells("D45:H45")
|
| 156 |
+
ws["D45"] = strengths
|
| 157 |
+
ws["D45"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 158 |
+
|
| 159 |
+
ws.merge_cells("D54:H54")
|
| 160 |
+
ws["D54"] = weaknesses
|
| 161 |
+
ws["D54"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 162 |
+
|
| 163 |
+
ws.merge_cells("D63:H63")
|
| 164 |
+
ws["D63"] = opportunities
|
| 165 |
+
ws["D63"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 166 |
+
|
| 167 |
+
ws.merge_cells("D72:H72")
|
| 168 |
+
ws["D72"] = threats
|
| 169 |
+
ws["D72"].alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 170 |
+
|
| 171 |
+
# ์์ ์ ์ฅ
|
| 172 |
+
output = BytesIO()
|
| 173 |
+
wb.save(output)
|
| 174 |
+
output.seek(0)
|
| 175 |
+
|
| 176 |
+
# overwrite EXE.xlsx
|
| 177 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 178 |
+
tmp.write(output.getvalue())
|
| 179 |
+
tmp.flush()
|
| 180 |
+
temp_file_path = tmp.name
|
| 181 |
+
|
| 182 |
+
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 183 |
+
os.rename(temp_file_path, final_path)
|
| 184 |
+
return final_path # ํ์ผ ๊ฒฝ๋ก ๋ฐํ
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def generate_financial_excel(
|
| 188 |
+
avg_monthly_sales,
|
| 189 |
+
rent,
|
| 190 |
+
labor_cost,
|
| 191 |
+
management_cost,
|
| 192 |
+
utilities,
|
| 193 |
+
current_interest,
|
| 194 |
+
other_cost,
|
| 195 |
+
cost_ratio
|
| 196 |
+
):
|
| 197 |
+
"""
|
| 198 |
+
๊ธฐ์กด run_generate_financial_excel() ๋ด์ฉ
|
| 199 |
+
(EX) 12๊ฐ ํญ๋ชฉ E87..G87 ~ E98..G98
|
| 200 |
+
"""
|
| 201 |
+
# 1) GPT ํธ์ถ
|
| 202 |
+
fin_result = analyze_financials(
|
| 203 |
+
avg_monthly_sales,
|
| 204 |
+
rent,
|
| 205 |
+
labor_cost,
|
| 206 |
+
management_cost,
|
| 207 |
+
utilities,
|
| 208 |
+
current_interest,
|
| 209 |
+
other_cost,
|
| 210 |
+
cost_ratio
|
| 211 |
+
)
|
| 212 |
+
# (์) ๊ฐ๊ฐ์๊ฐ๋น, ์์ด์ต์จ ๋ฑ ํ์ฑ ๋ก์ง
|
| 213 |
+
# ... (์๋ต)
|
| 214 |
+
|
| 215 |
+
# 2) ์์
์ ๊ธฐ๋ก (์์)
|
| 216 |
+
wb = load_workbook("EXE.xlsx")
|
| 217 |
+
ws = wb.active
|
| 218 |
+
|
| 219 |
+
# ws.merge_cells("E87:G87")
|
| 220 |
+
# ws["E87"] = f"์ํ๊ท ๋งค์ถ์ก: {avg_monthly_sales}"
|
| 221 |
+
# ...
|
| 222 |
+
# (์๋ต)
|
| 223 |
+
|
| 224 |
+
output = BytesIO()
|
| 225 |
+
wb.save(output)
|
| 226 |
+
output.seek(0)
|
| 227 |
|
| 228 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 229 |
+
tmp.write(output.getvalue())
|
| 230 |
+
tmp.flush()
|
| 231 |
+
temp_file_path = tmp.name
|
| 232 |
|
| 233 |
+
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 234 |
+
os.rename(temp_file_path, final_path)
|
| 235 |
+
return final_path
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def export_market_excel(region, industry):
|
| 239 |
+
"""
|
| 240 |
+
๊ธฐ์กด run_export_market_excel() ๋ด์ฉ
|
| 241 |
+
(์) ์๊ถ๋ถ์ ๊ฒฐ๊ณผ D101:H101
|
| 242 |
+
"""
|
| 243 |
+
# 1) GPT
|
| 244 |
+
market_result = analyze_market(region, industry)
|
| 245 |
+
|
| 246 |
+
# 2) ์์
๊ธฐ๋ก
|
| 247 |
+
wb = load_workbook("EXE.xlsx")
|
| 248 |
+
ws = wb.active
|
| 249 |
+
|
| 250 |
+
# ws.merge_cells("D101:H101")
|
| 251 |
+
# ws["D101"] = market_result
|
| 252 |
+
# ...
|
| 253 |
+
# (์๋ต)
|
| 254 |
+
|
| 255 |
+
output = BytesIO()
|
| 256 |
+
wb.save(output)
|
| 257 |
+
output.seek(0)
|
| 258 |
+
|
| 259 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 260 |
+
tmp.write(output.getvalue())
|
| 261 |
+
tmp.flush()
|
| 262 |
+
temp_file_path = tmp.name
|
| 263 |
+
|
| 264 |
+
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 265 |
+
os.rename(temp_file_path, final_path)
|
| 266 |
+
return final_path
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def generate_excel_top8_and_consulting(
|
| 270 |
+
consulting_company_rep,
|
| 271 |
+
consulting_address,
|
| 272 |
+
consulting_field,
|
| 273 |
+
client_name,
|
| 274 |
+
consulting_contact,
|
| 275 |
+
consulting_date_time,
|
| 276 |
+
consulting_round,
|
| 277 |
+
consulting_region,
|
| 278 |
+
photo1,
|
| 279 |
+
photo2,
|
| 280 |
+
preview_difficulties,
|
| 281 |
+
preview_goals
|
| 282 |
+
):
|
| 283 |
+
"""
|
| 284 |
+
๊ธฐ์กด run_generate_excel() ๋ด์ฉ
|
| 285 |
+
(์๋จ 8๊ฐ + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง)
|
| 286 |
+
"""
|
| 287 |
+
wb = load_workbook("EXE.xlsx")
|
| 288 |
+
ws = wb.active
|
| 289 |
|
| 290 |
+
# ... (์๋จ 8๊ฐ, D11, D22, B117/F117)
|
| 291 |
+
# (์๋ต)
|
| 292 |
+
|
| 293 |
+
output = BytesIO()
|
| 294 |
+
wb.save(output)
|
| 295 |
+
output.seek(0)
|
| 296 |
+
|
| 297 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 298 |
+
tmp.write(output.getvalue())
|
| 299 |
+
tmp.flush()
|
| 300 |
+
temp_file_path = tmp.name
|
| 301 |
+
|
| 302 |
+
final_path = os.path.join(os.path.dirname(temp_file_path), "EXE.xlsx")
|
| 303 |
+
os.rename(temp_file_path, final_path)
|
| 304 |
+
return final_path
|
| 305 |
|
| 306 |
############################
|
| 307 |
+
# (โ
) ์ต์ข
ํ๋์ ๋ฒํผ -> ์ ๊ธฐ๋ฅ๋ค ํ๊บผ๋ฒ์ ํธ์ถ
|
| 308 |
############################
|
| 309 |
+
def run_all_in_one(
|
| 310 |
+
# SWOT
|
| 311 |
+
strengths, weaknesses, opportunities, threats,
|
| 312 |
+
# ์ฌ๋ฌด๋ถ์
|
| 313 |
+
avg_monthly_sales, rent, labor_cost, management_cost, utilities, current_interest, other_cost, cost_ratio,
|
| 314 |
+
# ์๊ถ๋ถ์
|
| 315 |
+
region, industry,
|
| 316 |
+
# ์๋จ8 + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง
|
| 317 |
+
consulting_company_rep,
|
| 318 |
+
consulting_address,
|
| 319 |
+
consulting_field,
|
| 320 |
+
client_name,
|
| 321 |
+
consulting_contact,
|
| 322 |
+
consulting_date_time,
|
| 323 |
+
consulting_round,
|
| 324 |
+
consulting_region,
|
| 325 |
+
photo1,
|
| 326 |
+
photo2,
|
| 327 |
+
difficulties_input,
|
| 328 |
+
goals_input,
|
| 329 |
+
preview_difficulties_state,
|
| 330 |
+
preview_goals_state
|
| 331 |
+
):
|
| 332 |
+
"""
|
| 333 |
+
1) SWOT -> EXE.xlsx
|
| 334 |
+
2) ์ฌ๋ฌด๋ถ์ -> EXE.xlsx
|
| 335 |
+
3) ์๊ถ๋ถ์ -> EXE.xlsx
|
| 336 |
+
4) ์๋จ8 + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง -> EXE.xlsx
|
| 337 |
+
=> ์ต์ข
์์ฑ๋ EXE.xlsx ๊ฒฝ๋ก ๋ฆฌํด
|
| 338 |
+
"""
|
| 339 |
+
# 1) SWOT
|
| 340 |
+
export_swot_excel(strengths, weaknesses, opportunities, threats)
|
| 341 |
+
# 2) ์ฌ๋ฌด๋ถ์
|
| 342 |
+
generate_financial_excel(
|
| 343 |
+
avg_monthly_sales,
|
| 344 |
+
rent,
|
| 345 |
+
labor_cost,
|
| 346 |
+
management_cost,
|
| 347 |
+
utilities,
|
| 348 |
+
current_interest,
|
| 349 |
+
other_cost,
|
| 350 |
+
cost_ratio
|
| 351 |
+
)
|
| 352 |
+
# 3) ์๊ถ๋ถ์
|
| 353 |
+
export_market_excel(region, industry)
|
| 354 |
+
# 4) ์๋จ8 + ์ ๋ก์ฌํญ/๋ชฉํ + ์ฌ์ง
|
| 355 |
+
final_path = generate_excel_top8_and_consulting(
|
| 356 |
+
consulting_company_rep,
|
| 357 |
+
consulting_address,
|
| 358 |
+
consulting_field,
|
| 359 |
+
client_name,
|
| 360 |
+
consulting_contact,
|
| 361 |
+
consulting_date_time,
|
| 362 |
+
consulting_round,
|
| 363 |
+
consulting_region,
|
| 364 |
+
photo1,
|
| 365 |
+
photo2,
|
| 366 |
+
preview_difficulties_state,
|
| 367 |
+
preview_goals_state
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
+
return final_path
|
| 371 |
+
|
| 372 |
|
| 373 |
############################
|
| 374 |
# Gradio UI
|
| 375 |
############################
|
| 376 |
def main():
|
| 377 |
with gr.Blocks() as demo:
|
| 378 |
+
gr.Markdown("## (๋จ์ผ ํ์ด์ง) ๋ฒํผ ํ๋๋ก EXE.xlsx ๋ค์ด")
|
| 379 |
|
| 380 |
# [1] ์๋จ 8๊ฐ
|
| 381 |
with gr.Row():
|
|
|
|
| 395 |
# [2] ์ ๋ก์ฌํญ/๋ชฉํ
|
| 396 |
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 397 |
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
| 398 |
+
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 399 |
+
# ํ๋ฉด ํ์ ์์ด state์๋ง ์ ์ฅ
|
| 400 |
+
preview_difficulties_state = gr.State()
|
| 401 |
+
preview_goals_state = gr.State()
|
|
|
|
|
|
|
| 402 |
analyze_button.click(
|
| 403 |
fn=analyze_texts,
|
| 404 |
inputs=[difficulties_input, goals_input],
|
| 405 |
+
outputs=[preview_difficulties_state, preview_goals_state]
|
| 406 |
)
|
| 407 |
|
| 408 |
gr.Markdown("---")
|
|
|
|
| 420 |
opportunities_input = gr.Textbox(label="๊ธฐํ")
|
| 421 |
threats_input = gr.Textbox(label="์ํ")
|
| 422 |
|
| 423 |
+
# GPT๋ง ํธ์ถ, ๊ฒฐ๊ณผ state
|
| 424 |
swot_button = gr.Button("SWOT ๋ถ์ํ๊ธฐ")
|
| 425 |
+
swot_state = gr.State()
|
| 426 |
swot_button.click(
|
| 427 |
fn=analyze_swot,
|
| 428 |
inputs=[strengths_input, weaknesses_input, opportunities_input, threats_input],
|
| 429 |
+
outputs=[swot_state]
|
| 430 |
)
|
| 431 |
|
| 432 |
gr.Markdown("---")
|
|
|
|
| 444 |
other_cost_input = gr.Textbox(label="๊ธฐํ๋น์ฉ")
|
| 445 |
cost_ratio_input = gr.Textbox(label="์๊ฐ์จ")
|
| 446 |
|
| 447 |
+
# ํ๋ฉด ํ์ X. ๋จ์ง GPT ํธ์ถ์ ํ์ํ๋ค๋ฉด ๋ฒํผ ๋ง๋ค์ด๋ ๋จ
|
| 448 |
+
# (์๋ต)
|
| 449 |
|
| 450 |
gr.Markdown("---")
|
| 451 |
|
| 452 |
# [6] ์๊ถ๋ถ์
|
| 453 |
region_input = gr.Textbox(label="์ง์ญ")
|
| 454 |
industry_input = gr.Textbox(label="์
์ข
")
|
| 455 |
+
# ํ๋ฉด ํ์ X. GPT ํธ์ถ๋ง?
|
| 456 |
+
# (์๋ต)
|
| 457 |
|
| 458 |
gr.Markdown("---")
|
| 459 |
|
|
|
|
| 461 |
all_in_one_button = gr.Button("๋ชจ๋ ์
๋ ฅ ํ, Excel ๋ค์ด๋ก๋")
|
| 462 |
all_in_one_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญ ํ ์ ์ฅ)")
|
| 463 |
|
| 464 |
+
# ์ด ๋ฒํผ ํด๋ฆญ -> run_all_in_one
|
| 465 |
all_in_one_button.click(
|
| 466 |
fn=run_all_in_one,
|
| 467 |
inputs=[
|
|
|
|
| 498 |
photo_input_2,
|
| 499 |
difficulties_input,
|
| 500 |
goals_input,
|
| 501 |
+
preview_difficulties_state,
|
| 502 |
+
preview_goals_state
|
| 503 |
],
|
| 504 |
outputs=[all_in_one_file]
|
| 505 |
)
|