Spaces:
Sleeping
Sleeping
Update nlp.py
Browse files
nlp.py
CHANGED
@@ -6,7 +6,6 @@ import re
|
|
6 |
import os
|
7 |
import json
|
8 |
from datetime import datetime
|
9 |
-
from fastapi import UploadFile, File
|
10 |
from io import StringIO
|
11 |
|
12 |
def clean_kakao_message(text):
|
@@ -43,16 +42,16 @@ def analyze_sentiment(text, model, tokenizer):
|
|
43 |
|
44 |
return {"sentiment": sentiment, "confidence": confidence, "text": text}
|
45 |
|
46 |
-
async def analyze_kakao_csv(file
|
47 |
# 파일 내용 읽기 (bytes)
|
48 |
-
contents = await file.read()
|
49 |
|
50 |
# 1차: utf-8 시도
|
51 |
try:
|
52 |
-
df = pd.read_csv(StringIO(
|
53 |
except UnicodeDecodeError:
|
54 |
# 2차: cp949 시도
|
55 |
-
df = pd.read_csv(StringIO(
|
56 |
except Exception as e:
|
57 |
print(f"Error reading CSV: {e}")
|
58 |
return None
|
|
|
6 |
import os
|
7 |
import json
|
8 |
from datetime import datetime
|
|
|
9 |
from io import StringIO
|
10 |
|
11 |
def clean_kakao_message(text):
|
|
|
42 |
|
43 |
return {"sentiment": sentiment, "confidence": confidence, "text": text}
|
44 |
|
45 |
+
async def analyze_kakao_csv(file, model, tokenizer):
|
46 |
# 파일 내용 읽기 (bytes)
|
47 |
+
#contents = await file.read()
|
48 |
|
49 |
# 1차: utf-8 시도
|
50 |
try:
|
51 |
+
df = pd.read_csv(StringIO(file.decode("utf-8")))
|
52 |
except UnicodeDecodeError:
|
53 |
# 2차: cp949 시도
|
54 |
+
df = pd.read_csv(StringIO(file.decode("cp949")))
|
55 |
except Exception as e:
|
56 |
print(f"Error reading CSV: {e}")
|
57 |
return None
|