Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
| 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},
|
|
@@ -28,13 +28,33 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
|
|
| 28 |
)
|
| 29 |
return response.choices[0].message["content"]
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
######################
|
| 32 |
# ๋ถ์ ํจ์
|
| 33 |
######################
|
| 34 |
def analyze_texts(difficulties, goals):
|
| 35 |
"""
|
| 36 |
-
์ฌ์ฉ์ ์
๋ ฅ(์ ๋ก์ฌํญ, ์ปจ์คํ
๋ชฉํ)
|
| 37 |
-
|
| 38 |
"""
|
| 39 |
# ์ ๋ก์ฌํญ ๋ถ์
|
| 40 |
preview_difficulties = call_api(
|
|
@@ -59,53 +79,56 @@ def analyze_texts(difficulties, goals):
|
|
| 59 |
######################
|
| 60 |
def generate_excel(
|
| 61 |
# 8๊ฐ ์
๋ ฅ๊ฐ
|
| 62 |
-
consultant_name_rep,
|
| 63 |
-
consultant_contact,
|
| 64 |
-
consultant_address,
|
| 65 |
-
consultant_time,
|
| 66 |
-
consultant_field,
|
| 67 |
-
consultant_round,
|
| 68 |
-
consultant_client_name,
|
| 69 |
-
consultant_region,
|
| 70 |
|
| 71 |
# ์ฌ์ง 2๊ฐ
|
| 72 |
photo1,
|
| 73 |
photo2,
|
| 74 |
|
| 75 |
-
# ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์
|
| 76 |
preview_difficulties,
|
| 77 |
preview_goals
|
| 78 |
):
|
| 79 |
"""
|
| 80 |
-
1) EXE.xlsx ํ
ํ๋ฆฟ ๋ถ๋ฌ์ค๊ธฐ
|
| 81 |
-
2)
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
"""
|
| 86 |
-
wb = load_workbook("EXE.xlsx") # ํ
ํ๋ฆฟ
|
| 87 |
ws = wb.active
|
| 88 |
|
| 89 |
-
# (1)
|
| 90 |
-
ws
|
| 91 |
-
ws
|
| 92 |
-
ws
|
| 93 |
-
ws
|
| 94 |
-
ws
|
| 95 |
-
ws
|
| 96 |
-
ws
|
| 97 |
-
ws
|
| 98 |
|
| 99 |
# (2) ์ ๋ก์ฌํญ / ์ปจ์คํ
๋ชฉํ
|
| 100 |
-
ws
|
| 101 |
-
ws
|
| 102 |
|
| 103 |
-
# wrap_text & ์ปฌ๋ผ
|
|
|
|
| 104 |
ws["D11"].alignment = Alignment(wrap_text=True)
|
| 105 |
ws["D22"].alignment = Alignment(wrap_text=True)
|
| 106 |
ws.column_dimensions["D"].width = 42 # ๋๋ต 10cm ๊ทผ์ฌ
|
| 107 |
|
| 108 |
-
# (3) ์ฌ์ง
|
| 109 |
width_px = int(37.79 * 8) # 8cm
|
| 110 |
height_px = int(37.79 * 5) # 5cm
|
| 111 |
|
|
@@ -148,8 +171,7 @@ def generate_excel(
|
|
| 148 |
######################
|
| 149 |
def run_analyze(difficulties, goals):
|
| 150 |
"""
|
| 151 |
-
'๋ถ์ํ๊ธฐ'
|
| 152 |
-
gpt-4o-mini๋ก ๊ฐ๋จ ๋ถ์ -> ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
| 153 |
"""
|
| 154 |
preview_difficulties, preview_goals = analyze_texts(difficulties, goals)
|
| 155 |
return preview_difficulties, preview_goals
|
|
@@ -165,19 +187,18 @@ def run_generate_excel(
|
|
| 165 |
consultant_client_name,
|
| 166 |
consultant_region,
|
| 167 |
|
| 168 |
-
# ์ฌ์ง
|
| 169 |
photo1,
|
| 170 |
photo2,
|
| 171 |
|
| 172 |
-
# ์ ๋ก์ฌํญ/๋ชฉํ ์๋ฌธ
|
| 173 |
difficulties,
|
| 174 |
goals,
|
| 175 |
preview_difficulties,
|
| 176 |
preview_goals
|
| 177 |
):
|
| 178 |
"""
|
| 179 |
-
'์์
๋ก ๋ค์ด๋ก๋'
|
| 180 |
-
์ ์
๋ ฅ๋ค์ EXE.xlsx์ ๋ฐ์ -> ๋ค์ด๋ก๋
|
| 181 |
"""
|
| 182 |
excel_path = generate_excel(
|
| 183 |
consultant_name_rep,
|
|
@@ -202,7 +223,7 @@ def run_generate_excel(
|
|
| 202 |
######################
|
| 203 |
def create_app():
|
| 204 |
with gr.Blocks() as demo:
|
| 205 |
-
gr.Markdown("##
|
| 206 |
|
| 207 |
with gr.Row():
|
| 208 |
# ์ฒซ์งธ ์ค 4๊ฐ
|
|
@@ -220,19 +241,16 @@ def create_app():
|
|
| 220 |
|
| 221 |
gr.Markdown("---")
|
| 222 |
|
| 223 |
-
# ์ ๋ก์ฌํญ / ์ปจ์คํ
๋ชฉํ ์
๋ ฅ
|
| 224 |
with gr.Row():
|
| 225 |
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 226 |
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
| 227 |
|
| 228 |
gr.Markdown("---")
|
| 229 |
|
| 230 |
-
# ์ฌ์ง 2๊ฐ ์
๋ก๋ (๋ ๋ค '์์ง์
์ฒด์ฌ์ง')
|
| 231 |
with gr.Row():
|
| 232 |
photo_input_1 = gr.Image(label="์์ง์
์ฒด์ฌ์ง", type="pil")
|
| 233 |
photo_input_2 = gr.Image(label="์์ง์
์ฒด์ฌ์ง", type="pil")
|
| 234 |
|
| 235 |
-
# ๋ฒํผ๋ค
|
| 236 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 237 |
preview_difficulties_output = gr.Textbox(label="์ ๋ก์ฌํญ ๋ถ์ ๊ฒฐ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ", lines=3)
|
| 238 |
preview_goals_output = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ๋ถ์ ๊ฒฐ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ", lines=3)
|
|
@@ -240,14 +258,14 @@ def create_app():
|
|
| 240 |
download_button = gr.Button("์์
๋ก ๋ค์ด๋ก๋")
|
| 241 |
download_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญ ํ ์ ์ฅ)")
|
| 242 |
|
| 243 |
-
# [๋ถ์ํ๊ธฐ] ->
|
| 244 |
analyze_button.click(
|
| 245 |
fn=run_analyze,
|
| 246 |
inputs=[difficulties_input, goals_input],
|
| 247 |
outputs=[preview_difficulties_output, preview_goals_output]
|
| 248 |
)
|
| 249 |
|
| 250 |
-
# [์์
๋ก ๋ค์ด๋ก๋] ->
|
| 251 |
download_button.click(
|
| 252 |
fn=run_generate_excel,
|
| 253 |
inputs=[
|
|
|
|
| 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},
|
|
|
|
| 28 |
)
|
| 29 |
return response.choices[0].message["content"]
|
| 30 |
|
| 31 |
+
##################################################
|
| 32 |
+
# ๋ณํฉ๋ ์
์ ์์ ํ๊ฒ ๊ฐ ๋ฃ๋ ํฌํผ ํจ์
|
| 33 |
+
##################################################
|
| 34 |
+
def set_value_in_merged_cell(ws, cell_coordinate, value):
|
| 35 |
+
"""
|
| 36 |
+
๋ง์ฝ cell_coordinate (์: "D4")๊ฐ ๋ณํฉ๋ฒ์์ ํฌํจ๋์ด ์๋ค๋ฉด
|
| 37 |
+
๊ทธ ๋ณํฉ๋ฒ์์ top-left ์
(์: "C4")์ ๋์ value๋ฅผ ๊ธฐ๋กํ๋ค.
|
| 38 |
+
๋ณํฉ์ด ์๋๋ฉด cell_coordinate ๊ทธ๋๋ก ๊ธฐ๋กํ๋ค.
|
| 39 |
+
"""
|
| 40 |
+
for merged_range in ws.merged_cells.ranges:
|
| 41 |
+
# ์: merged_range.coord == "C4:D4"
|
| 42 |
+
if cell_coordinate in merged_range.coord:
|
| 43 |
+
# bounds = (min_col, min_row, max_col, max_row)
|
| 44 |
+
min_col, min_row, max_col, max_row = merged_range.bounds
|
| 45 |
+
top_left = ws.cell(row=min_row, column=min_col).coordinate
|
| 46 |
+
ws[top_left] = value
|
| 47 |
+
return
|
| 48 |
+
# ๋ณํฉ ์๋ ๊ฒฝ์ฐ ๊ทธ๋ฅ ์
|
| 49 |
+
ws[cell_coordinate] = value
|
| 50 |
+
|
| 51 |
######################
|
| 52 |
# ๋ถ์ ํจ์
|
| 53 |
######################
|
| 54 |
def analyze_texts(difficulties, goals):
|
| 55 |
"""
|
| 56 |
+
์ฌ์ฉ์ ์
๋ ฅ(์ ๋ก์ฌํญ, ์ปจ์คํ
๋ชฉํ)์ ๋ํด
|
| 57 |
+
gpt-4o-mini๋ก ๊ฐ๋จ ๋ถ์/์์ฝ -> ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ฐํ
|
| 58 |
"""
|
| 59 |
# ์ ๋ก์ฌํญ ๋ถ์
|
| 60 |
preview_difficulties = call_api(
|
|
|
|
| 79 |
######################
|
| 80 |
def generate_excel(
|
| 81 |
# 8๊ฐ ์
๋ ฅ๊ฐ
|
| 82 |
+
consultant_name_rep,
|
| 83 |
+
consultant_contact,
|
| 84 |
+
consultant_address,
|
| 85 |
+
consultant_time,
|
| 86 |
+
consultant_field,
|
| 87 |
+
consultant_round,
|
| 88 |
+
consultant_client_name,
|
| 89 |
+
consultant_region,
|
| 90 |
|
| 91 |
# ์ฌ์ง 2๊ฐ
|
| 92 |
photo1,
|
| 93 |
photo2,
|
| 94 |
|
| 95 |
+
# ์ ๋ก์ฌํญ/๋ชฉํ ๋ถ์๊ฒฐ๊ณผ
|
| 96 |
preview_difficulties,
|
| 97 |
preview_goals
|
| 98 |
):
|
| 99 |
"""
|
| 100 |
+
1) EXE.xlsx ํ
ํ๋ฆฟ ๋ถ๋ฌ์ค๊ธฐ (์๋ณธ ๋ณํฉ ์ ์ง)
|
| 101 |
+
2) D4,G4,D5,G5,D6,G6,D7,G7 -> 8๊ฐ ์
๋ ฅ๊ฐ
|
| 102 |
+
(๋จ, ๋ณํฉ ์
์ด๋ฉด top-left์ ๋์ ์ฐ๋๋ก set_value_in_merged_cell ํ์ฉ)
|
| 103 |
+
3) D11 -> ์ ๋ก์ฌํญ, D22 -> ์ปจ์คํ
๋ชฉํ
|
| 104 |
+
(wrap_text, 10cm ๊ทผ์ฌ์น ์ค์ )
|
| 105 |
+
4) B117 / F117 -> ์ฌ์ง(8cm x 5cm)
|
| 106 |
+
5) ๊ฒฐ๊ณผ EXE.xlsx๋ก ์ ์ฅ ํ ๊ฒฝ๋ก ๋ฐํ
|
| 107 |
"""
|
| 108 |
+
wb = load_workbook("EXE.xlsx") # ์๋ณธ ํ
ํ๋ฆฟ(๋ณํฉ ์ ์ง)
|
| 109 |
ws = wb.active
|
| 110 |
|
| 111 |
+
# (1) 8๊ฐ ์๋จ ์ ๋ณด
|
| 112 |
+
set_value_in_merged_cell(ws, "D4", consultant_name_rep)
|
| 113 |
+
set_value_in_merged_cell(ws, "G4", consultant_contact)
|
| 114 |
+
set_value_in_merged_cell(ws, "D5", consultant_address)
|
| 115 |
+
set_value_in_merged_cell(ws, "G5", consultant_time)
|
| 116 |
+
set_value_in_merged_cell(ws, "D6", consultant_field)
|
| 117 |
+
set_value_in_merged_cell(ws, "G6", consultant_round)
|
| 118 |
+
set_value_in_merged_cell(ws, "D7", consultant_client_name)
|
| 119 |
+
set_value_in_merged_cell(ws, "G7", consultant_region)
|
| 120 |
|
| 121 |
# (2) ์ ๋ก์ฌํญ / ์ปจ์คํ
๋ชฉํ
|
| 122 |
+
set_value_in_merged_cell(ws, "D11", preview_difficulties)
|
| 123 |
+
set_value_in_merged_cell(ws, "D22", preview_goals)
|
| 124 |
|
| 125 |
+
# wrap_text & ์ปฌ๋ผํญ
|
| 126 |
+
# "D11"๊ณผ "D22"๋ ๋์ผํ ์ปฌ๋ผ์ด๋ฏ๋ก ํญ๋ง ํ๋ฒ ์กฐ์
|
| 127 |
ws["D11"].alignment = Alignment(wrap_text=True)
|
| 128 |
ws["D22"].alignment = Alignment(wrap_text=True)
|
| 129 |
ws.column_dimensions["D"].width = 42 # ๋๋ต 10cm ๊ทผ์ฌ
|
| 130 |
|
| 131 |
+
# (3) ์ฌ์ง ์ฝ์
(B117, F117)
|
| 132 |
width_px = int(37.79 * 8) # 8cm
|
| 133 |
height_px = int(37.79 * 5) # 5cm
|
| 134 |
|
|
|
|
| 171 |
######################
|
| 172 |
def run_analyze(difficulties, goals):
|
| 173 |
"""
|
| 174 |
+
'๋ถ์ํ๊ธฐ' ํด๋ฆญ -> gpt-4o-mini ๊ฐ๋จ ์์ฝ
|
|
|
|
| 175 |
"""
|
| 176 |
preview_difficulties, preview_goals = analyze_texts(difficulties, goals)
|
| 177 |
return preview_difficulties, preview_goals
|
|
|
|
| 187 |
consultant_client_name,
|
| 188 |
consultant_region,
|
| 189 |
|
| 190 |
+
# ์ฌ์ง
|
| 191 |
photo1,
|
| 192 |
photo2,
|
| 193 |
|
| 194 |
+
# ์ ๋ก์ฌํญ / ๋ชฉํ ์๋ฌธ & ๋ถ์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
| 195 |
difficulties,
|
| 196 |
goals,
|
| 197 |
preview_difficulties,
|
| 198 |
preview_goals
|
| 199 |
):
|
| 200 |
"""
|
| 201 |
+
'์์
๋ก ๋ค์ด๋ก๋' -> ํ
ํ๋ฆฟ ๋ณํฉ ๊ทธ๋๋ก, top-left ์
๋ง ์ฐพ์ ๊ธฐ๋ก
|
|
|
|
| 202 |
"""
|
| 203 |
excel_path = generate_excel(
|
| 204 |
consultant_name_rep,
|
|
|
|
| 223 |
######################
|
| 224 |
def create_app():
|
| 225 |
with gr.Blocks() as demo:
|
| 226 |
+
gr.Markdown("## ๋ณํฉ ์ค๋ฅ ๋ฐฉ์ง: top-left ์
๋ง ์ฐพ์์ฐ๊ธฐ")
|
| 227 |
|
| 228 |
with gr.Row():
|
| 229 |
# ์ฒซ์งธ ์ค 4๊ฐ
|
|
|
|
| 241 |
|
| 242 |
gr.Markdown("---")
|
| 243 |
|
|
|
|
| 244 |
with gr.Row():
|
| 245 |
difficulties_input = gr.Textbox(label="์ ๋ก์ฌํญ ์
๋ ฅ", lines=3)
|
| 246 |
goals_input = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ์
๋ ฅ", lines=3)
|
| 247 |
|
| 248 |
gr.Markdown("---")
|
| 249 |
|
|
|
|
| 250 |
with gr.Row():
|
| 251 |
photo_input_1 = gr.Image(label="์์ง์
์ฒด์ฌ์ง", type="pil")
|
| 252 |
photo_input_2 = gr.Image(label="์์ง์
์ฒด์ฌ์ง", type="pil")
|
| 253 |
|
|
|
|
| 254 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 255 |
preview_difficulties_output = gr.Textbox(label="์ ๋ก์ฌํญ ๋ถ์ ๊ฒฐ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ", lines=3)
|
| 256 |
preview_goals_output = gr.Textbox(label="์ปจ์คํ
๋ชฉํ ๋ถ์ ๊ฒฐ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ", lines=3)
|
|
|
|
| 258 |
download_button = gr.Button("์์
๋ก ๋ค์ด๋ก๋")
|
| 259 |
download_file = gr.File(label="๋ค์ด๋ก๋(ํด๋ฆญ ํ ์ ์ฅ)")
|
| 260 |
|
| 261 |
+
# [๋ถ์ํ๊ธฐ] -> gpt-4o-mini ๋ถ์
|
| 262 |
analyze_button.click(
|
| 263 |
fn=run_analyze,
|
| 264 |
inputs=[difficulties_input, goals_input],
|
| 265 |
outputs=[preview_difficulties_output, preview_goals_output]
|
| 266 |
)
|
| 267 |
|
| 268 |
+
# [์์
๋ก ๋ค์ด๋ก๋] -> Excel ์์ฑ
|
| 269 |
download_button.click(
|
| 270 |
fn=run_generate_excel,
|
| 271 |
inputs=[
|