GitHub Actions
commited on
Commit
ยท
db7ff24
1
Parent(s):
51be5aa
Auto-deploy from GitHub Actions - 2025-12-12 15:13:03
Browse files- app/routes.py +106 -12
app/routes.py
CHANGED
|
@@ -5250,12 +5250,22 @@ def generate_detailed_tags(file_id):
|
|
| 5250 |
# ์ฌ๋ฌ ๋ฐฉ๋ฒ์ผ๋ก JSON ์ถ์ถ ์๋
|
| 5251 |
# ๋งํฌ๋ค์ด ์ฝ๋ ๋ธ๋ก ์ ๊ฑฐ (๋ ๊ฐ๋ ฅํ๊ฒ)
|
| 5252 |
cleaned_text = response_text
|
| 5253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5254 |
cleaned_text = re.sub(r'```json\s*\n?', '', cleaned_text, flags=re.IGNORECASE)
|
| 5255 |
cleaned_text = re.sub(r'```\s*\n?', '', cleaned_text)
|
| 5256 |
-
|
|
|
|
|
|
|
| 5257 |
cleaned_text = cleaned_text.strip()
|
| 5258 |
|
|
|
|
|
|
|
|
|
|
| 5259 |
# ๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ ์ ํํ JSON ์ถ์ถ ํจ์
|
| 5260 |
def extract_json_by_brackets(text):
|
| 5261 |
"""๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ์ฌ JSON ๊ฐ์ฒด ์ถ์ถ"""
|
|
@@ -5346,10 +5356,47 @@ def generate_detailed_tags(file_id):
|
|
| 5346 |
else:
|
| 5347 |
print(f"[์์ธ ํ๊ทธ ์์ฑ] JSON ํ์์ด ์๋ - ์ ์ฒด ์๋ต:")
|
| 5348 |
print(response_text)
|
| 5349 |
-
|
| 5350 |
-
|
| 5351 |
-
|
| 5352 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5353 |
except Exception as e:
|
| 5354 |
print(f"[์์ธ ํ๊ทธ ์์ฑ] ํ์ฑ ์ค๋ฅ: {str(e)}")
|
| 5355 |
import traceback
|
|
@@ -5679,12 +5726,22 @@ def generate_simple_tags(file_id):
|
|
| 5679 |
# ์ฌ๋ฌ ๋ฐฉ๋ฒ์ผ๋ก JSON ์ถ์ถ ์๋
|
| 5680 |
# ๋งํฌ๋ค์ด ์ฝ๋ ๋ธ๋ก ์ ๊ฑฐ (๋ ๊ฐ๋ ฅํ๊ฒ)
|
| 5681 |
cleaned_text = response_text
|
| 5682 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5683 |
cleaned_text = re.sub(r'```json\s*\n?', '', cleaned_text, flags=re.IGNORECASE)
|
| 5684 |
cleaned_text = re.sub(r'```\s*\n?', '', cleaned_text)
|
| 5685 |
-
|
|
|
|
|
|
|
| 5686 |
cleaned_text = cleaned_text.strip()
|
| 5687 |
|
|
|
|
|
|
|
|
|
|
| 5688 |
# ๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ ์ ํํ JSON ์ถ์ถ ํจ์
|
| 5689 |
def extract_json_by_brackets(text):
|
| 5690 |
"""๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ์ฌ JSON ๊ฐ์ฒด ์ถ์ถ"""
|
|
@@ -5773,10 +5830,47 @@ def generate_simple_tags(file_id):
|
|
| 5773 |
else:
|
| 5774 |
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] JSON ํ์์ด ์๋ - ์ ์ฒด ์๋ต:")
|
| 5775 |
print(response_text)
|
| 5776 |
-
|
| 5777 |
-
|
| 5778 |
-
|
| 5779 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5780 |
except Exception as e:
|
| 5781 |
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ํ์ฑ ์ค๋ฅ: {str(e)}")
|
| 5782 |
import traceback
|
|
|
|
| 5250 |
# ์ฌ๋ฌ ๋ฐฉ๋ฒ์ผ๋ก JSON ์ถ์ถ ์๋
|
| 5251 |
# ๋งํฌ๋ค์ด ์ฝ๋ ๋ธ๋ก ์ ๊ฑฐ (๋ ๊ฐ๋ ฅํ๊ฒ)
|
| 5252 |
cleaned_text = response_text
|
| 5253 |
+
|
| 5254 |
+
# ๋ฐฉ๋ฒ 1: ์ ์ฒด ์ฝ๋ ๋ธ๋ก ์ ๊ฑฐ (```json ... ```)
|
| 5255 |
+
cleaned_text = re.sub(r'```json\s*\n(.*?)\n```', r'\1', cleaned_text, flags=re.IGNORECASE | re.DOTALL)
|
| 5256 |
+
cleaned_text = re.sub(r'```\s*\n(.*?)\n```', r'\1', cleaned_text, flags=re.DOTALL)
|
| 5257 |
+
|
| 5258 |
+
# ๋ฐฉ๋ฒ 2: ์ฝ๋ ๋ธ๋ก ์์/๋ ๋ง์ปค ์ ๊ฑฐ
|
| 5259 |
cleaned_text = re.sub(r'```json\s*\n?', '', cleaned_text, flags=re.IGNORECASE)
|
| 5260 |
cleaned_text = re.sub(r'```\s*\n?', '', cleaned_text)
|
| 5261 |
+
cleaned_text = re.sub(r'\n?```\s*$', '', cleaned_text, flags=re.MULTILINE)
|
| 5262 |
+
|
| 5263 |
+
# ๋ฐฉ๋ฒ 3: ์๋ค ๊ณต๋ฐฑ ๋ฐ ์ค๋ฐ๊ฟ ์ ๊ฑฐ
|
| 5264 |
cleaned_text = cleaned_text.strip()
|
| 5265 |
|
| 5266 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ๋งํฌ๋ค์ด ์ ๊ฑฐ ํ ํ
์คํธ ๊ธธ์ด: {len(cleaned_text)} ๋ฌธ์")
|
| 5267 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ๋งํฌ๋ค์ด ์ ๊ฑฐ ํ ์ฒ์ 300์: {cleaned_text[:300]}")
|
| 5268 |
+
|
| 5269 |
# ๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ ์ ํํ JSON ์ถ์ถ ํจ์
|
| 5270 |
def extract_json_by_brackets(text):
|
| 5271 |
"""๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ์ฌ JSON ๊ฐ์ฒด ์ถ์ถ"""
|
|
|
|
| 5356 |
else:
|
| 5357 |
print(f"[์์ธ ํ๊ทธ ์์ฑ] JSON ํ์์ด ์๋ - ์ ์ฒด ์๋ต:")
|
| 5358 |
print(response_text)
|
| 5359 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ๋งํฌ๋ค์ด ์ ๊ฑฐ ํ ํ
์คํธ:")
|
| 5360 |
+
print(cleaned_text)
|
| 5361 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ์ฒซ ๋ฒ์งธ {{ ์์น: {cleaned_text.find('{')}")
|
| 5362 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ์ฒซ ๋ฒ์งธ }} ์์น: {cleaned_text.find('}')}")
|
| 5363 |
+
|
| 5364 |
+
# ์ตํ์ ์๋จ: ์๋ณธ์์ ์ง์ { ์ฐพ์์ ์ถ์ถ ์๋
|
| 5365 |
+
if '{' in cleaned_text:
|
| 5366 |
+
start_idx = cleaned_text.find('{')
|
| 5367 |
+
# ๊ดํธ ๋งค์นญ์ผ๋ก ๋ค์ ์๋
|
| 5368 |
+
depth = 0
|
| 5369 |
+
for i in range(start_idx, len(cleaned_text)):
|
| 5370 |
+
if cleaned_text[i] == '{':
|
| 5371 |
+
depth += 1
|
| 5372 |
+
elif cleaned_text[i] == '}':
|
| 5373 |
+
depth -= 1
|
| 5374 |
+
if depth == 0:
|
| 5375 |
+
json_str = cleaned_text[start_idx:i+1]
|
| 5376 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ์ตํ์ ์๋จ์ผ๋ก JSON ์ถ์ถ ์๋, ๊ธธ์ด: {len(json_str)}")
|
| 5377 |
+
try:
|
| 5378 |
+
tags_data = json.loads(json_str)
|
| 5379 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ์ตํ์ ์๋จ์ผ๋ก JSON ํ์ฑ ์ฑ๊ณต!")
|
| 5380 |
+
except Exception as e:
|
| 5381 |
+
print(f"[์์ธ ํ๊ทธ ์์ฑ] ์ตํ์ ์๋จ๋ ์คํจ: {e}")
|
| 5382 |
+
return jsonify({
|
| 5383 |
+
'error': 'AI ์๋ต์ด ์ฌ๋ฐ๋ฅธ JSON ํ์์ด ์๋๋๋ค.',
|
| 5384 |
+
'response_preview': response_text[:500] if len(response_text) > 500 else response_text,
|
| 5385 |
+
'cleaned_preview': cleaned_text[:500] if len(cleaned_text) > 500 else cleaned_text
|
| 5386 |
+
}), 500
|
| 5387 |
+
break
|
| 5388 |
+
else:
|
| 5389 |
+
return jsonify({
|
| 5390 |
+
'error': 'AI ์๋ต์ด ์ฌ๋ฐ๋ฅธ JSON ํ์์ด ์๋๋๋ค.',
|
| 5391 |
+
'response_preview': response_text[:500] if len(response_text) > 500 else response_text,
|
| 5392 |
+
'cleaned_preview': cleaned_text[:500] if len(cleaned_text) > 500 else cleaned_text
|
| 5393 |
+
}), 500
|
| 5394 |
+
else:
|
| 5395 |
+
return jsonify({
|
| 5396 |
+
'error': 'AI ์๋ต์ด ์ฌ๋ฐ๋ฅธ JSON ํ์์ด ์๋๋๋ค.',
|
| 5397 |
+
'response_preview': response_text[:500] if len(response_text) > 500 else response_text,
|
| 5398 |
+
'cleaned_preview': cleaned_text[:500] if len(cleaned_text) > 500 else cleaned_text
|
| 5399 |
+
}), 500
|
| 5400 |
except Exception as e:
|
| 5401 |
print(f"[์์ธ ํ๊ทธ ์์ฑ] ํ์ฑ ์ค๋ฅ: {str(e)}")
|
| 5402 |
import traceback
|
|
|
|
| 5726 |
# ์ฌ๋ฌ ๋ฐฉ๋ฒ์ผ๋ก JSON ์ถ์ถ ์๋
|
| 5727 |
# ๋งํฌ๋ค์ด ์ฝ๋ ๋ธ๋ก ์ ๊ฑฐ (๋ ๊ฐ๋ ฅํ๊ฒ)
|
| 5728 |
cleaned_text = response_text
|
| 5729 |
+
|
| 5730 |
+
# ๋ฐฉ๋ฒ 1: ์ ์ฒด ์ฝ๋ ๋ธ๋ก ์ ๊ฑฐ (```json ... ```)
|
| 5731 |
+
cleaned_text = re.sub(r'```json\s*\n(.*?)\n```', r'\1', cleaned_text, flags=re.IGNORECASE | re.DOTALL)
|
| 5732 |
+
cleaned_text = re.sub(r'```\s*\n(.*?)\n```', r'\1', cleaned_text, flags=re.DOTALL)
|
| 5733 |
+
|
| 5734 |
+
# ๋ฐฉ๋ฒ 2: ์ฝ๋ ๋ธ๋ก ์์/๋ ๋ง์ปค ์ ๊ฑฐ
|
| 5735 |
cleaned_text = re.sub(r'```json\s*\n?', '', cleaned_text, flags=re.IGNORECASE)
|
| 5736 |
cleaned_text = re.sub(r'```\s*\n?', '', cleaned_text)
|
| 5737 |
+
cleaned_text = re.sub(r'\n?```\s*$', '', cleaned_text, flags=re.MULTILINE)
|
| 5738 |
+
|
| 5739 |
+
# ๋ฐฉ๋ฒ 3: ์๋ค ๊ณต๋ฐฑ ๋ฐ ์ค๋ฐ๊ฟ ์ ๊ฑฐ
|
| 5740 |
cleaned_text = cleaned_text.strip()
|
| 5741 |
|
| 5742 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ๋งํฌ๋ค์ด ์ ๊ฑฐ ํ ํ
์คํธ ๊ธธ์ด: {len(cleaned_text)} ๋ฌธ์")
|
| 5743 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ๋งํฌ๋ค์ด ์ ๊ฑฐ ํ ์ฒ์ 300์: {cleaned_text[:300]}")
|
| 5744 |
+
|
| 5745 |
# ๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ ์ ํํ JSON ์ถ์ถ ํจ์
|
| 5746 |
def extract_json_by_brackets(text):
|
| 5747 |
"""๊ดํธ ๋งค์นญ์ ์ฌ์ฉํ์ฌ JSON ๊ฐ์ฒด ์ถ์ถ"""
|
|
|
|
| 5830 |
else:
|
| 5831 |
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] JSON ํ์์ด ์๋ - ์ ์ฒด ์๋ต:")
|
| 5832 |
print(response_text)
|
| 5833 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ๋งํฌ๋ค์ด ์ ๊ฑฐ ํ ํ
์คํธ:")
|
| 5834 |
+
print(cleaned_text)
|
| 5835 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ์ฒซ ๋ฒ์งธ { ์์น: {cleaned_text.find('{')}")
|
| 5836 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ์ฒซ ๋ฒ์งธ } ์์น: {cleaned_text.find('}')}")
|
| 5837 |
+
|
| 5838 |
+
# ์ตํ์ ์๋จ: ์๋ณธ์์ ์ง์ { ์ฐพ์์ ์ถ์ถ ์๋
|
| 5839 |
+
if '{' in cleaned_text:
|
| 5840 |
+
start_idx = cleaned_text.find('{')
|
| 5841 |
+
# ๊ดํธ ๋งค์นญ์ผ๋ก ๋ค์ ์๋
|
| 5842 |
+
depth = 0
|
| 5843 |
+
for i in range(start_idx, len(cleaned_text)):
|
| 5844 |
+
if cleaned_text[i] == '{':
|
| 5845 |
+
depth += 1
|
| 5846 |
+
elif cleaned_text[i] == '}':
|
| 5847 |
+
depth -= 1
|
| 5848 |
+
if depth == 0:
|
| 5849 |
+
json_str = cleaned_text[start_idx:i+1]
|
| 5850 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ์ตํ์ ์๋จ์ผ๋ก JSON ์ถ์ถ ์๋, ๊ธธ์ด: {len(json_str)}")
|
| 5851 |
+
try:
|
| 5852 |
+
tags_data = json.loads(json_str)
|
| 5853 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ์ตํ์ ์๋จ์ผ๋ก JSON ํ์ฑ ์ฑ๊ณต!")
|
| 5854 |
+
except Exception as e:
|
| 5855 |
+
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ์ตํ์ ์๋จ๋ ์คํจ: {e}")
|
| 5856 |
+
return jsonify({
|
| 5857 |
+
'error': 'AI ์๋ต์ด ์ฌ๋ฐ๋ฅธ JSON ํ์์ด ์๋๋๋ค.',
|
| 5858 |
+
'response_preview': response_text[:500] if len(response_text) > 500 else response_text,
|
| 5859 |
+
'cleaned_preview': cleaned_text[:500] if len(cleaned_text) > 500 else cleaned_text
|
| 5860 |
+
}), 500
|
| 5861 |
+
break
|
| 5862 |
+
else:
|
| 5863 |
+
return jsonify({
|
| 5864 |
+
'error': 'AI ์๋ต์ด ์ฌ๋ฐ๋ฅธ JSON ํ์์ด ์๋๋๋ค.',
|
| 5865 |
+
'response_preview': response_text[:500] if len(response_text) > 500 else response_text,
|
| 5866 |
+
'cleaned_preview': cleaned_text[:500] if len(cleaned_text) > 500 else cleaned_text
|
| 5867 |
+
}), 500
|
| 5868 |
+
else:
|
| 5869 |
+
return jsonify({
|
| 5870 |
+
'error': 'AI ์๋ต์ด ์ฌ๋ฐ๋ฅธ JSON ํ์์ด ์๋๋๋ค.',
|
| 5871 |
+
'response_preview': response_text[:500] if len(response_text) > 500 else response_text,
|
| 5872 |
+
'cleaned_preview': cleaned_text[:500] if len(cleaned_text) > 500 else cleaned_text
|
| 5873 |
+
}), 500
|
| 5874 |
except Exception as e:
|
| 5875 |
print(f"[์ผ๋ฐ ํ๊ทธ ์์ฑ] ํ์ฑ ์ค๋ฅ: {str(e)}")
|
| 5876 |
import traceback
|