S-Dreamer commited on
Commit
ec547e8
·
verified ·
1 Parent(s): 8ebb3ac

Upload 01_Dataset_Management.py

Browse files
Files changed (1) hide show
  1. 01_Dataset_Management.py +124 -0
01_Dataset_Management.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import time
4
+ from data_utils import process_python_dataset, list_available_datasets, get_dataset_info
5
+ from utils import set_page_config, display_sidebar, add_log
6
+
7
+ # Set page configuration
8
+ set_page_config()
9
+
10
+ # Display sidebar
11
+ display_sidebar()
12
+
13
+ # Title
14
+ st.title("Dataset Management")
15
+ st.markdown("Upload and manage your Python code datasets for model training.")
16
+
17
+ # Create tabs for different dataset operations
18
+ tab1, tab2 = st.tabs(["Upload Dataset", "View Datasets"])
19
+
20
+ with tab1:
21
+ st.subheader("Upload a New Dataset")
22
+
23
+ # Dataset name input
24
+ dataset_name = st.text_input("Dataset Name", placeholder="e.g., python_functions")
25
+
26
+ # File uploader
27
+ uploaded_file = st.file_uploader(
28
+ "Upload Python Code Dataset",
29
+ type=["py", "json", "csv"],
30
+ help="Upload Python code files (.py), JSON files containing code snippets, or CSV files with code columns"
31
+ )
32
+
33
+ # Dataset upload options
34
+ col1, col2 = st.columns(2)
35
+ with col1:
36
+ st.markdown("### Dataset Format")
37
+ st.markdown("""
38
+ - **Python files (.py)**: Will be split into examples by function/class definitions
39
+ - **JSON files (.json)**: Should contain a list of objects with a 'code' field
40
+ - **CSV files (.csv)**: Should have a 'code' column
41
+ """)
42
+
43
+ with col2:
44
+ st.markdown("### Processing Options")
45
+ auto_split = st.checkbox("Automatically split into train/validation sets", value=True)
46
+ split_ratio = st.slider("Validation Split Ratio", min_value=0.1, max_value=0.3, value=0.2, step=0.05, disabled=not auto_split)
47
+
48
+ # Process button
49
+ if st.button("Process Dataset"):
50
+ if not dataset_name:
51
+ st.error("Please provide a dataset name")
52
+ elif not uploaded_file:
53
+ st.error("Please upload a file")
54
+ elif dataset_name in list_available_datasets():
55
+ st.error(f"Dataset with name '{dataset_name}' already exists. Please choose a different name.")
56
+ else:
57
+ with st.spinner("Processing dataset..."):
58
+ success = process_python_dataset(uploaded_file, dataset_name)
59
+ if success:
60
+ st.success(f"Dataset '{dataset_name}' processed successfully!")
61
+ add_log(f"Dataset '{dataset_name}' uploaded and processed")
62
+ time.sleep(1)
63
+ st.experimental_rerun()
64
+ else:
65
+ st.error("Failed to process dataset. Check logs for details.")
66
+
67
+ with tab2:
68
+ st.subheader("Available Datasets")
69
+
70
+ # Get available datasets
71
+ available_datasets = list_available_datasets()
72
+
73
+ if not available_datasets:
74
+ st.info("No datasets available. Upload a dataset in the 'Upload Dataset' tab.")
75
+ else:
76
+ # Dataset selection
77
+ selected_dataset = st.selectbox("Select a Dataset", available_datasets)
78
+
79
+ if selected_dataset:
80
+ # Get dataset info
81
+ dataset_info = get_dataset_info(selected_dataset)
82
+
83
+ if dataset_info:
84
+ # Display dataset information
85
+ col1, col2 = st.columns(2)
86
+
87
+ with col1:
88
+ st.markdown("### Dataset Information")
89
+ st.markdown(f"**Name:** {dataset_info['name']}")
90
+ st.markdown(f"**Total Examples:** {dataset_info['size']}")
91
+ st.markdown(f"**Training Examples:** {dataset_info['train_size']}")
92
+ st.markdown(f"**Validation Examples:** {dataset_info['validation_size']}")
93
+ st.markdown(f"**Created:** {dataset_info['created_at']}")
94
+
95
+ with col2:
96
+ st.markdown("### Dataset Structure")
97
+ columns = dataset_info.get('columns', [])
98
+ for col in columns:
99
+ st.markdown(f"- {col}")
100
+
101
+ # Display sample data
102
+ st.markdown("### Sample Data")
103
+
104
+ # Get the dataset
105
+ dataset = st.session_state.datasets[selected_dataset]['data']
106
+
107
+ # Display first few examples
108
+ if 'train' in dataset and len(dataset['train']) > 0:
109
+ sample_size = min(5, len(dataset['train']))
110
+ for i in range(sample_size):
111
+ with st.expander(f"Example {i+1}"):
112
+ st.code(dataset['train'][i].get('code', '# No code available'), language='python')
113
+ else:
114
+ st.info("No examples available to display")
115
+
116
+ # Actions
117
+ st.markdown("### Actions")
118
+ if st.button("Delete Dataset", key="delete_dataset"):
119
+ if selected_dataset in st.session_state.datasets:
120
+ del st.session_state.datasets[selected_dataset]
121
+ add_log(f"Dataset '{selected_dataset}' deleted")
122
+ st.success(f"Dataset '{selected_dataset}' deleted successfully!")
123
+ time.sleep(1)
124
+ st.rerun()