Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -158,23 +158,55 @@ def main():
|
|
| 158 |
|
| 159 |
# Sidebar Configuration with Additional Options
|
| 160 |
with st.sidebar:
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
# Load Dataset
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
# Start Training with Progress Bar
|
| 180 |
progress_placeholder = st.empty()
|
|
|
|
| 158 |
|
| 159 |
# Sidebar Configuration with Additional Options
|
| 160 |
with st.sidebar:
|
| 161 |
+
st.markdown("### Configuration Panel")
|
| 162 |
+
|
| 163 |
+
# Hugging Face API Token Input
|
| 164 |
+
hf_token = st.text_input("Enter your Hugging Face Token", type="password")
|
| 165 |
+
if hf_token:
|
| 166 |
+
api = HfApi()
|
| 167 |
+
api.set_access_token(hf_token)
|
| 168 |
+
st.success("Hugging Face token added successfully!")
|
| 169 |
+
|
| 170 |
+
# Training Parameters
|
| 171 |
+
training_epochs = st.slider("Training Epochs", min_value=1, max_value=5, value=3)
|
| 172 |
+
batch_size = st.slider("Batch Size", min_value=2, max_value=8, value=4)
|
| 173 |
+
model_choice = st.selectbox("Model Selection", ("gpt2", "distilgpt2", "gpt2-medium"))
|
| 174 |
+
|
| 175 |
+
# Dataset Source Selection
|
| 176 |
+
data_source = st.selectbox("Data Source", ("demo", "uploaded file"))
|
| 177 |
+
if data_source == "uploaded file":
|
| 178 |
+
uploaded_file = st.file_uploader("Upload a text file", type=["txt", "csv"])
|
| 179 |
+
|
| 180 |
+
custom_learning_rate = st.slider("Learning Rate", min_value=1e-6, max_value=5e-4, value=3e-5, step=1e-6)
|
| 181 |
+
|
| 182 |
+
# Advanced Settings Toggle
|
| 183 |
+
advanced_toggle = st.checkbox("Advanced Training Settings")
|
| 184 |
+
if advanced_toggle:
|
| 185 |
+
warmup_steps = st.slider("Warmup Steps", min_value=0, max_value=500, value=100)
|
| 186 |
+
weight_decay = st.slider("Weight Decay", min_value=0.0, max_value=0.1, step=0.01, value=0.01)
|
| 187 |
+
else:
|
| 188 |
+
warmup_steps = 100
|
| 189 |
+
weight_decay = 0.01
|
| 190 |
+
|
| 191 |
|
| 192 |
# Load Dataset
|
| 193 |
+
train_dataset = load_dataset(data_source, tokenizer, uploaded_file=uploaded_file)
|
| 194 |
+
def load_dataset(data_source="demo", tokenizer=None, uploaded_file=None):
|
| 195 |
+
if data_source == "demo":
|
| 196 |
+
data = ["Sample text data for model training. This can be replaced with actual data for better performance."]
|
| 197 |
+
elif uploaded_file is not None:
|
| 198 |
+
if uploaded_file.name.endswith(".txt"):
|
| 199 |
+
data = [uploaded_file.read().decode("utf-8")]
|
| 200 |
+
elif uploaded_file.name.endswith(".csv"):
|
| 201 |
+
import pandas as pd
|
| 202 |
+
df = pd.read_csv(uploaded_file)
|
| 203 |
+
data = df[df.columns[0]].tolist() # assuming first column is text data
|
| 204 |
+
else:
|
| 205 |
+
data = ["No file uploaded. Please upload a dataset."]
|
| 206 |
+
|
| 207 |
+
dataset = prepare_dataset(data, tokenizer)
|
| 208 |
+
return dataset
|
| 209 |
+
|
| 210 |
|
| 211 |
# Start Training with Progress Bar
|
| 212 |
progress_placeholder = st.empty()
|