Spaces:
Sleeping
Sleeping
Shubham 10000 commited on
Commit ·
ce5f6a5
1
Parent(s): 2495ef5
path change for img
Browse files- src/file_manage.py +12 -24
src/file_manage.py
CHANGED
|
@@ -1,33 +1,21 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import os
|
| 3 |
-
|
| 4 |
-
SAVE_DIR = 'uploads'
|
| 5 |
-
os.makedirs(SAVE_DIR, exist_ok=True)
|
| 6 |
|
| 7 |
def upload_csv():
|
| 8 |
-
uploaded_file = st.file_uploader("Choose a CSV file",type="csv")
|
| 9 |
-
|
| 10 |
if uploaded_file is not None:
|
| 11 |
-
# Save
|
| 12 |
-
save_path = os.path.join(
|
| 13 |
-
with open(save_path,
|
| 14 |
f.write(uploaded_file.getbuffer())
|
| 15 |
-
st.success(f"File
|
| 16 |
-
|
| 17 |
def list_files():
|
| 18 |
-
|
| 19 |
-
files = os.listdir(
|
| 20 |
if files:
|
|
|
|
| 21 |
for file in files:
|
| 22 |
-
|
| 23 |
-
col1.write(file)
|
| 24 |
-
if col2.button("Delete", key=file):
|
| 25 |
-
os.remove(os.path.join('uploads',file))
|
| 26 |
-
st.success(f'File {file} deleted successfully!')
|
| 27 |
-
st.rerun()
|
| 28 |
else:
|
| 29 |
-
st.
|
| 30 |
-
|
| 31 |
-
return files
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import streamlit as st
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def upload_csv():
|
| 5 |
+
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
|
|
|
| 6 |
if uploaded_file is not None:
|
| 7 |
+
# Save to /tmp for Hugging Face Spaces compatibility
|
| 8 |
+
save_path = os.path.join("/tmp", uploaded_file.name)
|
| 9 |
+
with open(save_path, "wb") as f:
|
| 10 |
f.write(uploaded_file.getbuffer())
|
| 11 |
+
st.success(f"File saved to {save_path}")
|
| 12 |
+
|
| 13 |
def list_files():
|
| 14 |
+
# List files in /tmp directory
|
| 15 |
+
files = [f for f in os.listdir("/tmp") if f.endswith(".csv")]
|
| 16 |
if files:
|
| 17 |
+
st.write("Uploaded CSV files:")
|
| 18 |
for file in files:
|
| 19 |
+
st.write(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
else:
|
| 21 |
+
st.write("No CSV files found in /tmp.")
|
|
|
|
|
|
|
|
|
|
|
|