Update app.py
Browse files
app.py
CHANGED
@@ -54,17 +54,41 @@ def read_uploaded_file(file):
|
|
54 |
content = df.head(10).to_markdown(index=False)
|
55 |
return content, "parquet"
|
56 |
elif file_ext == '.csv':
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
else:
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
except Exception as e:
|
69 |
return f"ํ์ผ์ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "error"
|
70 |
|
|
|
54 |
content = df.head(10).to_markdown(index=False)
|
55 |
return content, "parquet"
|
56 |
elif file_ext == '.csv':
|
57 |
+
# CSV ํ์ผ ์ฝ๊ธฐ ์ ๋ค์ํ ์ธ์ฝ๋ฉ ์๋
|
58 |
+
encodings = ['utf-8', 'cp949', 'euc-kr', 'latin1']
|
59 |
+
for encoding in encodings:
|
60 |
+
try:
|
61 |
+
df = pd.read_csv(file.name, encoding=encoding)
|
62 |
+
content = f"๋ฐ์ดํฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ:\n{df.head(10).to_markdown(index=False)}\n\n"
|
63 |
+
content += f"\n๋ฐ์ดํฐ ์ ๋ณด:\n"
|
64 |
+
content += f"- ์ด ํ ์: {len(df)}\n"
|
65 |
+
content += f"- ์ด ์ด ์: {len(df.columns)}\n"
|
66 |
+
content += f"- ์ปฌ๋ผ ๋ชฉ๋ก: {', '.join(df.columns)}\n"
|
67 |
+
# ๋ฐ์ดํฐ ํ์
์ ๋ณด ์ถ๊ฐ
|
68 |
+
content += f"\n์ปฌ๋ผ๋ณ ๋ฐ์ดํฐ ํ์
:\n"
|
69 |
+
for col, dtype in df.dtypes.items():
|
70 |
+
content += f"- {col}: {dtype}\n"
|
71 |
+
# ๊ฒฐ์ธก์น ์ ๋ณด ์ถ๊ฐ
|
72 |
+
null_counts = df.isnull().sum()
|
73 |
+
if null_counts.any():
|
74 |
+
content += f"\n๊ฒฐ์ธก์น ์ ๋ณด:\n"
|
75 |
+
for col, null_count in null_counts[null_counts > 0].items():
|
76 |
+
content += f"- {col}: {null_count}๊ฐ\n"
|
77 |
+
return content, "csv"
|
78 |
+
except UnicodeDecodeError:
|
79 |
+
continue
|
80 |
+
raise UnicodeDecodeError(f"์ง์๋๋ ์ธ์ฝ๋ฉ({', '.join(encodings)})์ผ๋ก ํ์ผ์ ์ฝ์ ์ ์์ต๋๋ค.")
|
81 |
else:
|
82 |
+
# ํ
์คํธ ํ์ผ ์ฝ๊ธฐ ์๋
|
83 |
+
encodings = ['utf-8', 'cp949', 'euc-kr', 'latin1']
|
84 |
+
for encoding in encodings:
|
85 |
+
try:
|
86 |
+
with open(file.name, 'r', encoding=encoding) as f:
|
87 |
+
content = f.read()
|
88 |
+
return content, "text"
|
89 |
+
except UnicodeDecodeError:
|
90 |
+
continue
|
91 |
+
raise UnicodeDecodeError(f"์ง์๋๋ ์ธ์ฝ๋ฉ({', '.join(encodings)})์ผ๋ก ํ์ผ์ ์ฝ์ ์ ์์ต๋๋ค.")
|
92 |
except Exception as e:
|
93 |
return f"ํ์ผ์ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "error"
|
94 |
|