Update app.py
Browse files5 unmodified lines6789101183 unmodified lines95969798991001011021031041051061071081091101111121131141151161175 unmodified linesimport jsonimport osimport gradio as gr# Pathsimage_folder = "Images/"83 unmodified linesif batch_idx % 10 == 0: # Log every 10 batchesprint(f"Batch {batch_idx}, Loss: {loss.item()}")# Define the folder where the model will be savedsave_folder = "models"os.makedirs(save_folder, exist_ok=True) # Create the folder if it doesn't exist# Save the trained model in the specified foldermodel_save_path = os.path.join(save_folder, "lora_model.pth")torch.save(model.state_dict(), model_save_path)print(f"Model saved at {model_save_path}")print("Training completed.")# Gradio Appdef start_training_gradio():print("Loading metadata and preparing dataset...")metadata = load_metadata(metadata_file)train_lora(image_folder, metadata)return "Training completed. Check the model outputs!"demo = gr.Interface(fn=start_training_gradio,5 unmodified lines678910111283 unmodified lines969798991001011021031041051061071081091101111121131141151161175 unmodified linesimport jsonimport osimport gradio as grimport shutil# Pathsimage_folder = "Images/"83 unmodified linesif batch_idx % 10 == 0: # Log every 10 batchesprint(f"Batch {batch_idx}, Loss: {loss.item()}")# Save the trained model to /mnt/data/ for Hugging Face Space to accesssave_path = '/mnt/data/lora_model.pth'torch.save(model.state_dict(), save_path)print(f"Model saved at {save_path}")# Move the file to a location where we can access it for download# Here, /mnt/data is directly accessible from the Hugging Face Space interfaceprint(f"Training completed. The model is saved and ready for download at {save_path}.")return f"Training completed. Download the model from: [Download Model](sandbox:/mnt/data/lora_model.pth)"# Gradio Appdef start_training_gradio():print("Loading metadata and preparing dataset...")metadata = load_metadata(metadata_file)return train_lora(image_folder, metadata)demo = gr.Interface(fn=start_training_gradio,
app.py+10-10