Update app.py
Browse files
app.py
CHANGED
@@ -65,51 +65,6 @@ def preprocess_single_chunk(chunk: str) -> str:
|
|
65 |
except Exception as e:
|
66 |
return f"์ฒญํฌ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
67 |
|
68 |
-
def preprocess_text_with_llm(input_text: str) -> str:
|
69 |
-
if not input_text.strip():
|
70 |
-
return "์
๋ ฅ ํ
์คํธ๊ฐ ๋น์ด์์ต๋๋ค."
|
71 |
-
|
72 |
-
try:
|
73 |
-
# ํ
์คํธ๋ฅผ ์ฒญํฌ๋ก ๋ถํ
|
74 |
-
chunks = chunk_text(input_text)
|
75 |
-
|
76 |
-
# ๋ณ๋ ฌ ์ฒ๋ฆฌ๋ก ์ฒญํฌ๋ค์ ์ฒ๋ฆฌ
|
77 |
-
with ThreadPoolExecutor(max_workers=3) as executor:
|
78 |
-
processed_chunks = list(executor.map(cached_preprocess, chunks))
|
79 |
-
|
80 |
-
# ๊ฒฐ๊ณผ ๋ณํฉ ๋ฐ ์ค๋ณต ์ ๊ฑฐ
|
81 |
-
all_lines = []
|
82 |
-
seen_texts = set()
|
83 |
-
current_id = 1
|
84 |
-
|
85 |
-
for chunk_result in processed_chunks:
|
86 |
-
lines = chunk_result.split('\n')
|
87 |
-
for line in lines:
|
88 |
-
line = line.strip()
|
89 |
-
if line and '์ถ๋ ฅ:' not in line and line not in seen_texts:
|
90 |
-
# ID ์ฌํ ๋น
|
91 |
-
parts = line.split(',', 1)
|
92 |
-
if len(parts) > 1:
|
93 |
-
new_line = f"{current_id},{parts[1]}"
|
94 |
-
all_lines.append(new_line)
|
95 |
-
seen_texts.add(new_line)
|
96 |
-
current_id += 1
|
97 |
-
|
98 |
-
processed_text = '\n'.join(all_lines)
|
99 |
-
|
100 |
-
# CSV ํ์ ๊ฒ์ฆ
|
101 |
-
try:
|
102 |
-
from io import StringIO
|
103 |
-
import csv
|
104 |
-
csv.reader(StringIO(processed_text))
|
105 |
-
return processed_text
|
106 |
-
except csv.Error:
|
107 |
-
return "LLM์ด ์ฌ๋ฐ๋ฅธ CSV ํ์์ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์."
|
108 |
-
|
109 |
-
except Exception as e:
|
110 |
-
error_message = f"์ ์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
111 |
-
print(error_message)
|
112 |
-
return error_message
|
113 |
|
114 |
|
115 |
|
@@ -278,6 +233,7 @@ def text_to_parquet(text: str) -> Tuple[str, str, str]:
|
|
278 |
print(f"{error_message}\n{traceback.format_exc()}")
|
279 |
return error_message, "", ""
|
280 |
|
|
|
281 |
def preprocess_text_with_llm(input_text: str) -> str:
|
282 |
if not input_text.strip():
|
283 |
return "์
๋ ฅ ํ
์คํธ๊ฐ ๋น์ด์์ต๋๋ค."
|
@@ -310,40 +266,50 @@ def preprocess_text_with_llm(input_text: str) -> str:
|
|
310 |
- ๊ฐ ํ์ ์๋ก์ด ์ค๋ก ๊ตฌ๋ถ
|
311 |
- ๋ถํ์ํ ๋ฐ๋ณต ์ถ๋ ฅ ๊ธ์ง"""
|
312 |
|
313 |
-
full_prompt = f"{system_prompt}\n\n์
๋ ฅํ
์คํธ:\n{input_text}\n\n์ถ๋ ฅ:"
|
314 |
-
|
315 |
try:
|
316 |
-
|
317 |
-
|
318 |
-
prompt=full_prompt,
|
319 |
-
max_new_tokens=4000,
|
320 |
-
temperature=0.1, # ๋ ๊ฒฐ์ ์ ์ธ ์ถ๋ ฅ์ ์ํด ๋ฎ์ถค
|
321 |
-
top_p=0.9,
|
322 |
-
stream=True,
|
323 |
-
)
|
324 |
|
325 |
-
|
326 |
-
|
327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
|
329 |
-
#
|
330 |
-
|
331 |
-
processed_text = response.split("<EOS_TOKEN>")[0].strip()
|
332 |
-
else:
|
333 |
-
processed_text = response.strip()
|
334 |
-
|
335 |
-
# ์ค๋ณต ์ถ๋ ฅ ์ ๊ฑฐ
|
336 |
-
lines = processed_text.split('\n')
|
337 |
-
unique_lines = []
|
338 |
seen_texts = set()
|
|
|
339 |
|
340 |
-
for
|
341 |
-
|
342 |
-
if
|
343 |
-
|
344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
|
346 |
-
processed_text = '\n'.join(
|
347 |
|
348 |
# CSV ํ์ ๊ฒ์ฆ
|
349 |
try:
|
@@ -359,6 +325,7 @@ def preprocess_text_with_llm(input_text: str) -> str:
|
|
359 |
print(error_message)
|
360 |
return error_message
|
361 |
|
|
|
362 |
# CSS ์ค์
|
363 |
css = """
|
364 |
footer {
|
|
|
65 |
except Exception as e:
|
66 |
return f"์ฒญํฌ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
|
70 |
|
|
|
233 |
print(f"{error_message}\n{traceback.format_exc()}")
|
234 |
return error_message, "", ""
|
235 |
|
236 |
+
|
237 |
def preprocess_text_with_llm(input_text: str) -> str:
|
238 |
if not input_text.strip():
|
239 |
return "์
๋ ฅ ํ
์คํธ๊ฐ ๋น์ด์์ต๋๋ค."
|
|
|
266 |
- ๊ฐ ํ์ ์๋ก์ด ์ค๋ก ๊ตฌ๋ถ
|
267 |
- ๋ถํ์ํ ๋ฐ๋ณต ์ถ๋ ฅ ๊ธ์ง"""
|
268 |
|
|
|
|
|
269 |
try:
|
270 |
+
# ํ
์คํธ๋ฅผ ์ฒญํฌ๋ก ๋ถํ
|
271 |
+
chunks = chunk_text(input_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
+
# ๋ณ๋ ฌ ์ฒ๋ฆฌ๋ก ์ฒญํฌ๋ค์ ์ฒ๋ฆฌ
|
274 |
+
with ThreadPoolExecutor(max_workers=3) as executor:
|
275 |
+
processed_chunks = []
|
276 |
+
for chunk in chunks:
|
277 |
+
# ๊ฐ ์ฒญํฌ์ ๋ํ ํ๋กฌํํธ ์์ฑ
|
278 |
+
chunk_prompt = f"{system_prompt}\n\n์
๋ ฅํ
์คํธ:\n{chunk}\n\n์ถ๋ ฅ:"
|
279 |
+
future = executor.submit(
|
280 |
+
hf_client.text_generation,
|
281 |
+
prompt=chunk_prompt,
|
282 |
+
max_new_tokens=2000,
|
283 |
+
temperature=0.1,
|
284 |
+
top_p=0.5,
|
285 |
+
stream=False
|
286 |
+
)
|
287 |
+
processed_chunks.append(future.result())
|
288 |
|
289 |
+
# ๊ฒฐ๊ณผ ๋ณํฉ ๋ฐ ์ค๋ณต ์ ๊ฑฐ
|
290 |
+
all_lines = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
seen_texts = set()
|
292 |
+
current_id = 1
|
293 |
|
294 |
+
for chunk_result in processed_chunks:
|
295 |
+
# EOS_TOKEN ์ฒ๋ฆฌ
|
296 |
+
if "<EOS_TOKEN>" in chunk_result:
|
297 |
+
chunk_result = chunk_result.split("<EOS_TOKEN>")[0]
|
298 |
+
|
299 |
+
lines = chunk_result.strip().split('\n')
|
300 |
+
for line in lines:
|
301 |
+
line = line.strip()
|
302 |
+
if line and '์ถ๋ ฅ:' not in line and line not in seen_texts:
|
303 |
+
# ID ์ฌํ ๋น
|
304 |
+
parts = line.split(',', 1)
|
305 |
+
if len(parts) > 1:
|
306 |
+
new_line = f"{current_id},{parts[1]}"
|
307 |
+
if new_line not in seen_texts: # ์ถ๊ฐ์ ์ธ ์ค๋ณต ๊ฒ์ฌ
|
308 |
+
all_lines.append(new_line)
|
309 |
+
seen_texts.add(new_line)
|
310 |
+
current_id += 1
|
311 |
|
312 |
+
processed_text = '\n'.join(all_lines)
|
313 |
|
314 |
# CSV ํ์ ๊ฒ์ฆ
|
315 |
try:
|
|
|
325 |
print(error_message)
|
326 |
return error_message
|
327 |
|
328 |
+
|
329 |
# CSS ์ค์
|
330 |
css = """
|
331 |
footer {
|