Tanusree88 commited on
Commit
9edd29b
·
verified ·
1 Parent(s): 68257a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -70,6 +70,7 @@ def fine_tune_model(train_loader):
70
  criterion = torch.nn.CrossEntropyLoss()
71
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
72
  model.to(device)
 
73
  for epoch in range(10):
74
  running_loss = 0.0
75
  for images, labels in train_loader:
@@ -85,10 +86,25 @@ def fine_tune_model(train_loader):
85
  # Streamlit UI
86
  st.title("Fine-tune ViT on MRI Scans")
87
 
 
 
 
 
88
  if st.button("Start Training"):
89
- extract_zip('https://huggingface.co/spaces/Tanusree88/ViT-MRI-FineTuning/resolve/main/archive%20(5).zip', '')
90
- image_paths, labels = prepare_dataset('extracted_folder/')
 
 
 
 
 
 
 
 
91
  dataset = CustomImageDataset(image_paths, labels)
92
  train_loader = DataLoader(dataset, batch_size=32, shuffle=True)
 
 
93
  final_loss = fine_tune_model(train_loader)
94
  st.write(f"Training Complete with Final Loss: {final_loss}")
 
 
70
  criterion = torch.nn.CrossEntropyLoss()
71
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
72
  model.to(device)
73
+
74
  for epoch in range(10):
75
  running_loss = 0.0
76
  for images, labels in train_loader:
 
86
  # Streamlit UI
87
  st.title("Fine-tune ViT on MRI Scans")
88
 
89
+ # Input for zip file paths
90
+ zip_file_1 = st.text_input("https://huggingface.co/spaces/Tanusree88/ViT-MRI-FineTuning/resolve/main/archive%20(5).zip")
91
+ zip_file_2 = st.text_input("https://huggingface.co/spaces/Tanusree88/ViT-MRI-FineTuning/resolve/main/MS.zip")
92
+
93
  if st.button("Start Training"):
94
+ # Define an extraction directory
95
+ extraction_dir = 'extracted_folder/'
96
+ os.makedirs(extraction_dir, exist_ok=True)
97
+
98
+ # Extract both zip files
99
+ extract_zip(zip_file_1, extraction_dir)
100
+ extract_zip(zip_file_2, extraction_dir)
101
+
102
+ # Prepare dataset
103
+ image_paths, labels = prepare_dataset(extraction_dir)
104
  dataset = CustomImageDataset(image_paths, labels)
105
  train_loader = DataLoader(dataset, batch_size=32, shuffle=True)
106
+
107
+ # Fine-tune the model
108
  final_loss = fine_tune_model(train_loader)
109
  st.write(f"Training Complete with Final Loss: {final_loss}")
110
+