nileshhanotia commited on
Commit
8ad732e
1 Parent(s): 3c13618

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -4,7 +4,11 @@ import streamlit as st
4
  from transformers import AutoTokenizer, AutoModelForCausalLM, Trainer, TrainingArguments
5
  from transformers import DataCollatorForLanguageModeling
6
  import torch
7
- from tqdm import tqdm
 
 
 
 
8
 
9
  @st.cache_data
10
  def load_data(file_path):
@@ -64,6 +68,9 @@ def main():
64
  num_epochs = st.number_input("Enter number of training epochs", min_value=1, max_value=10, value=3)
65
  batch_size = st.number_input("Enter batch size", min_value=1, max_value=32, value=8)
66
  learning_rate = st.number_input("Enter learning rate", min_value=1e-6, max_value=1e-3, value=5e-5, format="%.1e")
 
 
 
67
 
68
  tokenizer, model = initialize_model_and_tokenizer(model_name)
69
 
@@ -118,19 +125,25 @@ def main():
118
  if st.button('Start Training'):
119
  st.write("Starting training...")
120
  progress_bar = st.progress(0)
 
 
 
121
 
122
  for epoch in range(int(num_epochs)):
123
  trainer.train()
124
  progress = (epoch + 1) / num_epochs
125
  progress_bar.progress(progress)
126
 
127
- # Save the model after each epoch
128
  model_path = f"./results/model_epoch_{epoch+1}"
129
  trainer.save_model(model_path)
130
- st.write(f"Model saved: {model_path}")
 
 
 
 
131
 
132
- st.write("Training complete.")
133
- st.write("You can now use the trained model for inference or further fine-tuning.")
134
 
135
  if __name__ == "__main__":
136
- main()
 
4
  from transformers import AutoTokenizer, AutoModelForCausalLM, Trainer, TrainingArguments
5
  from transformers import DataCollatorForLanguageModeling
6
  import torch
7
+ from huggingface_hub import Repository, HfFolder
8
+
9
+ # Authenticate Hugging Face Hub
10
+ hf_token = st.secrets["hf_token"] # Store your token in the Hugging Face Space Secrets
11
+ HfFolder.save_token(hf_token)
12
 
13
  @st.cache_data
14
  def load_data(file_path):
 
68
  num_epochs = st.number_input("Enter number of training epochs", min_value=1, max_value=10, value=3)
69
  batch_size = st.number_input("Enter batch size", min_value=1, max_value=32, value=8)
70
  learning_rate = st.number_input("Enter learning rate", min_value=1e-6, max_value=1e-3, value=5e-5, format="%.1e")
71
+
72
+ # Specify your Hugging Face model repository ID
73
+ repo_id = st.text_input("Enter Hugging Face repository ID", "nileshhanotia/PeVe")
74
 
75
  tokenizer, model = initialize_model_and_tokenizer(model_name)
76
 
 
125
  if st.button('Start Training'):
126
  st.write("Starting training...")
127
  progress_bar = st.progress(0)
128
+
129
+ # Initialize the Hugging Face repository
130
+ repo = Repository(local_dir="./results", clone_from=repo_id)
131
 
132
  for epoch in range(int(num_epochs)):
133
  trainer.train()
134
  progress = (epoch + 1) / num_epochs
135
  progress_bar.progress(progress)
136
 
137
+ # Save the model after each epoch locally
138
  model_path = f"./results/model_epoch_{epoch+1}"
139
  trainer.save_model(model_path)
140
+ st.write(f"Model saved locally: {model_path}")
141
+
142
+ # Push to Hugging Face Hub
143
+ repo.push_to_hub(commit_message=f"Model after epoch {epoch+1}")
144
+ st.write(f"Model pushed to Hugging Face Hub: {repo_id}")
145
 
146
+ st.write("Training complete. Model is available on the Hugging Face Hub.")
 
147
 
148
  if __name__ == "__main__":
149
+ main()