Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1057,52 +1057,7 @@ async def enhance_text_with_ai(text_content: str, title: str) -> str:
|
|
1057 |
# ์๋ณธ ํ
์คํธ ๊ทธ๋๋ก ๋ฐํ (AI ํฅ์ ๊ธฐ๋ฅ ๋นํ์ฑํ)
|
1058 |
return text_content
|
1059 |
|
1060 |
-
|
1061 |
-
# ์ปจํ
์คํธ ํฌ๊ธฐ๋ฅผ ๊ณ ๋ คํ์ฌ ํ
์คํธ๊ฐ ๋๋ฌด ๊ธธ๋ฉด ์๋ถ๋ถ๋ง ์ฌ์ฉ
|
1062 |
-
max_context_length = 60000
|
1063 |
-
if len(text_content) > max_context_length:
|
1064 |
-
text_to_process = text_content[:max_context_length] + "...(์ดํ ์๋ต)"
|
1065 |
-
else:
|
1066 |
-
text_to_process = text_content
|
1067 |
-
|
1068 |
-
# OpenAI API ํธ์ถํ์ฌ ํ
์คํธ ๊ตฌ์กฐํ
|
1069 |
-
try:
|
1070 |
-
system_prompt = """
|
1071 |
-
๋น์ ์ ํ
์คํธ๋ฅผ ์ ๊ตฌ์กฐํ๋ ์ ์์ฑ
ํ์์ผ๋ก ๋ณํํ๋ ์ ๋ฌธ๊ฐ์
๋๋ค.
|
1072 |
-
์ ๊ณต๋ ์๋ณธ ํ
์คํธ๋ฅผ ๋ถ์ํ๊ณ , ๋ค์๊ณผ ๊ฐ์ด ๊ฐ์ ํด์ฃผ์ธ์:
|
1073 |
-
|
1074 |
-
1. ๋
ผ๋ฆฌ์ ์ธ ์น์
์ผ๋ก ๋๋๊ณ ์ ์ ํ ์ ๋ชฉ๊ณผ ๋ถ์ ๋ชฉ ์ถ๊ฐ
|
1075 |
-
2. ๋จ๋ฝ์ ์์ฐ์ค๋ฝ๊ฒ ๊ตฌ์ฑํ๊ณ ๊ฐ๋
์ฑ ๊ฐ์
|
1076 |
-
3. ์ค์ํ ๋ด์ฉ์ ๊ฐ์กฐํ๊ฑฐ๋ ์์ฝํ์ฌ ํ์
|
1077 |
-
4. ์๋ณธ ๋ด์ฉ์ ์๋ฏธ์ ๋งฅ๋ฝ์ ์ ์งํ๋ฉด์ ๊น๋ํ๊ฒ ์ ๋ฆฌ
|
1078 |
-
5. ๋ง์ถค๋ฒ๊ณผ ๋ฌธ๋ฒ ์ค๋ฅ ์์
|
1079 |
-
|
1080 |
-
์๋ณธ ๋ด์ฉ์ ๋ชจ๋ ์ ์งํ๋, ์ ์ ๋ฆฌ๋ ์ ์์ฑ
์ฒ๋ผ ๋ณด์ด๋๋ก ๊ตฌ์กฐํํด์ฃผ์ธ์.
|
1081 |
-
์์ ๋ณธ์ ์ง์ ๋ฐํํ๊ณ , ์๋ณธ ๋ด์ฉ์ ๋ชจ๋ ํฌํจํด์ผ ํฉ๋๋ค.
|
1082 |
-
"""
|
1083 |
-
|
1084 |
-
response = openai_client.chat.completions.create(
|
1085 |
-
model="gpt-4.1-mini",
|
1086 |
-
messages=[
|
1087 |
-
{"role": "system", "content": system_prompt},
|
1088 |
-
{"role": "user", "content": f"์ ๋ชฉ: {title}\n\n์๋ณธ ํ
์คํธ:\n{text_to_process}"}
|
1089 |
-
],
|
1090 |
-
temperature=0.7,
|
1091 |
-
max_tokens=4000,
|
1092 |
-
timeout=60.0
|
1093 |
-
)
|
1094 |
-
|
1095 |
-
enhanced_text = response.choices[0].message.content
|
1096 |
-
return enhanced_text
|
1097 |
-
|
1098 |
-
except Exception as api_error:
|
1099 |
-
logger.error(f"AI ํ
์คํธ ํฅ์ ์ค๋ฅ: {api_error}")
|
1100 |
-
# ์ค๋ฅ ๋ฐ์ ์ ์๋ณธ ํ
์คํธ ๋ฐํ
|
1101 |
-
return text_content
|
1102 |
-
|
1103 |
-
except Exception as e:
|
1104 |
-
logger.error(f"AI ํ
์คํธ ํฅ์ ์ค๋ฅ: {e}")
|
1105 |
-
return text_content
|
1106 |
|
1107 |
# ํ
์คํธ ํ์ผ์ PDF๋ก ๋ณํํ๋ ์๋ํฌ์ธํธ
|
1108 |
@app.post("/api/text-to-pdf")
|
|
|
1057 |
# ์๋ณธ ํ
์คํธ ๊ทธ๋๋ก ๋ฐํ (AI ํฅ์ ๊ธฐ๋ฅ ๋นํ์ฑํ)
|
1058 |
return text_content
|
1059 |
|
1060 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1061 |
|
1062 |
# ํ
์คํธ ํ์ผ์ PDF๋ก ๋ณํํ๋ ์๋ํฌ์ธํธ
|
1063 |
@app.post("/api/text-to-pdf")
|