Spaces:
Sleeping
Sleeping
Update routes.py
Browse files
routes.py
CHANGED
@@ -111,7 +111,7 @@ def get_report_details(report_name):
|
|
111 |
|
112 |
@main_bp.route('/explain', methods=['POST'])
|
113 |
def explain_sentence():
|
114 |
-
"""
|
115 |
if not llm_is_initialized():
|
116 |
logger.error("LLM ํด๋ผ์ด์ธํธ(REST API)๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค. ์์ฒญ์ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.")
|
117 |
return jsonify({"error": "LLM ํด๋ผ์ด์ธํธ(REST API)๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค. API ํค์ ๋ฒ ์ด์ค URL์ ํ์ธํ์ธ์."}), 500
|
@@ -140,22 +140,6 @@ def explain_sentence():
|
|
140 |
logger.error(f"๋ณด๊ณ ์ '{report_name}'์ ์ค์ ์์ ์ด๋ฏธ์ง ๋๋ ๋ณด๊ณ ์ ํ์ผ ๊ฒฝ๋ก(static ๊ธฐ์ค ์๋๊ฒฝ๋ก)๊ฐ ๋๋ฝ๋์์ต๋๋ค.")
|
141 |
return jsonify({"error": f"๋ณด๊ณ ์ '{report_name}'์ ํ์ผ ์ค์ ์ด ๋๋ฝ๋์์ต๋๋ค."}), 500
|
142 |
|
143 |
-
# Construct absolute server paths using BASE_DIR as image_file and report_file include "static/"
|
144 |
-
server_image_path = config.BASE_DIR / image_file
|
145 |
-
|
146 |
-
|
147 |
-
# --- Prepare Base64 Image for API ---
|
148 |
-
if not server_image_path.is_file():
|
149 |
-
logger.error(f"์ด๋ฏธ์ง ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค: {server_image_path}")
|
150 |
-
return jsonify({"error": f"๋ณด๊ณ ์ '{report_name}'์ ์ด๋ฏธ์ง ํ์ผ์ ์๋ฒ์์ ์ฐพ์ ์ ์์ต๋๋ค."}), 500
|
151 |
-
|
152 |
-
base64_image_data_url = utils.image_to_base64_data_url(str(server_image_path))
|
153 |
-
if not base64_image_data_url:
|
154 |
-
logger.error("์ด๋ฏธ์ง๋ฅผ base64๋ก ์ธ์ฝ๋ฉํ๋๋ฐ ์คํจํ์ต๋๋ค.")
|
155 |
-
return jsonify({"error": "API ์์ฒญ์ ์ํ ์ด๋ฏธ์ง ์ธ์ฝ๋ฉ์ ์คํจํ์ต๋๋ค"}), 500
|
156 |
-
|
157 |
-
logger.info("API๋ฅผ ์ํ base64 ๋ฐ์ดํฐ URL๋ก ์ด๋ฏธ์ง๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ธ์ฝ๋ฉ๋์์ต๋๋ค.")
|
158 |
-
|
159 |
full_report_text = ""
|
160 |
if report_file: # Only attempt to read if a report file is configured
|
161 |
server_report_path = config.BASE_DIR / report_file
|
@@ -187,13 +171,9 @@ def explain_sentence():
|
|
187 |
)
|
188 |
user_prompt_text = f"๋ฐฉ์ฌ์ ๋ณด๊ณ ์์ ์ด ๋ฌธ์ฅ์ ์ค๋ช
ํด์ฃผ์ธ์: '{selected_sentence}'"
|
189 |
|
190 |
-
# API๋ ์ด๋ฏธ์ง๋ฅผ ์ง์ ๋ฐ์ง ๋ชปํ๋ฏ๋ก ํ
์คํธ๋ง ์ ์ก
|
191 |
messages_for_api = [
|
192 |
{"role": "system", "content": system_prompt},
|
193 |
-
{
|
194 |
-
"role": "user",
|
195 |
-
"content": user_prompt_text # ํ
์คํธ๋ง ์ ์ก
|
196 |
-
}
|
197 |
]
|
198 |
|
199 |
# ํ๊ธ ์๋ต์ ์ํด ์บ์ ํค์ ์ธ์ด ์ ๋ณด ์ถ๊ฐ
|
@@ -204,7 +184,7 @@ def explain_sentence():
|
|
204 |
return jsonify({"explanation": cached_result})
|
205 |
|
206 |
try:
|
207 |
-
logger.info("
|
208 |
response = make_chat_completion_request(
|
209 |
model="tgi",
|
210 |
messages=messages_for_api,
|
@@ -298,10 +278,7 @@ def upload_and_analyze():
|
|
298 |
|
299 |
messages_for_api = [
|
300 |
{"role": "system", "content": system_prompt},
|
301 |
-
{
|
302 |
-
"role": "user",
|
303 |
-
"content": user_prompt_text # ํ
์คํธ๋ง ์ ์ก
|
304 |
-
}
|
305 |
]
|
306 |
|
307 |
# ์บ์ ํค ์์ฑ (ํ์ผ๋ช
๊ณผ ์ปจํ
์คํธ ๊ธฐ๋ฐ)
|
|
|
111 |
|
112 |
@main_bp.route('/explain', methods=['POST'])
|
113 |
def explain_sentence():
|
114 |
+
"""LLM API๋ฅผ ์ฌ์ฉํ์ฌ ์ค๋ช
์์ฒญ์ ์ฒ๋ฆฌํฉ๋๋ค."""
|
115 |
if not llm_is_initialized():
|
116 |
logger.error("LLM ํด๋ผ์ด์ธํธ(REST API)๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค. ์์ฒญ์ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.")
|
117 |
return jsonify({"error": "LLM ํด๋ผ์ด์ธํธ(REST API)๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค. API ํค์ ๋ฒ ์ด์ค URL์ ํ์ธํ์ธ์."}), 500
|
|
|
140 |
logger.error(f"๋ณด๊ณ ์ '{report_name}'์ ์ค์ ์์ ์ด๋ฏธ์ง ๋๋ ๋ณด๊ณ ์ ํ์ผ ๊ฒฝ๋ก(static ๊ธฐ์ค ์๋๊ฒฝ๋ก)๊ฐ ๋๋ฝ๋์์ต๋๋ค.")
|
141 |
return jsonify({"error": f"๋ณด๊ณ ์ '{report_name}'์ ํ์ผ ์ค์ ์ด ๋๋ฝ๋์์ต๋๋ค."}), 500
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
full_report_text = ""
|
144 |
if report_file: # Only attempt to read if a report file is configured
|
145 |
server_report_path = config.BASE_DIR / report_file
|
|
|
171 |
)
|
172 |
user_prompt_text = f"๋ฐฉ์ฌ์ ๋ณด๊ณ ์์ ์ด ๋ฌธ์ฅ์ ์ค๋ช
ํด์ฃผ์ธ์: '{selected_sentence}'"
|
173 |
|
|
|
174 |
messages_for_api = [
|
175 |
{"role": "system", "content": system_prompt},
|
176 |
+
{"role": "user", "content": user_prompt_text}
|
|
|
|
|
|
|
177 |
]
|
178 |
|
179 |
# ํ๊ธ ์๋ต์ ์ํด ์บ์ ํค์ ์ธ์ด ์ ๋ณด ์ถ๊ฐ
|
|
|
184 |
return jsonify({"explanation": cached_result})
|
185 |
|
186 |
try:
|
187 |
+
logger.info("LLM API(REST)๋ก ์์ฒญ์ ์ ์ก ์ค...")
|
188 |
response = make_chat_completion_request(
|
189 |
model="tgi",
|
190 |
messages=messages_for_api,
|
|
|
278 |
|
279 |
messages_for_api = [
|
280 |
{"role": "system", "content": system_prompt},
|
281 |
+
{"role": "user", "content": user_prompt_text}
|
|
|
|
|
|
|
282 |
]
|
283 |
|
284 |
# ์บ์ ํค ์์ฑ (ํ์ผ๋ช
๊ณผ ์ปจํ
์คํธ ๊ธฐ๋ฐ)
|