OmPrakashSingh1704 commited on
Commit
cff43cf
1 Parent(s): 5869ab0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -4
app.py CHANGED
@@ -28,22 +28,68 @@ if not os.path.exists(clone_path):
28
  # Step 3: Update submodules
29
  run_command(['git', 'submodule', 'update', '--init', '--recursive'], cwd=repo_dir)
30
 
31
- # Step 6: Install torch and torchvision
32
  run_command([sys.executable, '-m', 'pip', 'install', 'torch', 'torchvision', '--index-url', 'https://download.pytorch.org/whl/cu121'], cwd=repo_dir)
33
 
34
- # Step 7: Install dependencies from requirements.txt
35
  run_command([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'], cwd=repo_dir)
36
 
37
- from huggingface_hub import login
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
 
39
  login(token=os.getenv("TOKEN"))
40
 
41
- # Run the flux_train_ui.py file
42
  run_command([sys.executable, 'flux_train_ui.py'], cwd=repo_dir)
43
 
44
  print("Setup completed successfully.")
45
  else:
 
 
 
 
 
 
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  run_command([sys.executable, 'flux_train_ui.py'], cwd=repo_dir)
48
 
49
  print("The 'ai-toolkit' directory already exists. No need to clone.")
 
28
  # Step 3: Update submodules
29
  run_command(['git', 'submodule', 'update', '--init', '--recursive'], cwd=repo_dir)
30
 
31
+ # Step 4: Install torch and torchvision
32
  run_command([sys.executable, '-m', 'pip', 'install', 'torch', 'torchvision', '--index-url', 'https://download.pytorch.org/whl/cu121'], cwd=repo_dir)
33
 
34
+ # Step 5: Install dependencies from requirements.txt
35
  run_command([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'], cwd=repo_dir)
36
 
37
+ # Step 6: Install mediapipe (to handle the missing dependency)
38
+ run_command([sys.executable, '-m', 'pip', 'install', 'mediapipe'], cwd=repo_dir)
39
+
40
+ # Step 7: Modify the flux_train_ui.py to handle Gradio share and CUDA availability issues
41
+
42
+ flux_train_ui_path = os.path.join(repo_dir, 'flux_train_ui.py')
43
+
44
+ # Ensure Gradio does not try to set share=True
45
+ with open(flux_train_ui_path, 'r') as file:
46
+ lines = file.readlines()
47
+
48
+ with open(flux_train_ui_path, 'w') as file:
49
+ for line in lines:
50
+ # Modify Gradio 'share=True' to 'share=False'
51
+ if 'launch(share=True)' in line:
52
+ line = line.replace('share=True', 'share=False')
53
+ file.write(line)
54
+
55
+ # Modify flux_train_ui.py to handle CUDA availability for torch
56
+ with open(flux_train_ui_path, 'a') as file:
57
+ file.write('\nimport torch\n')
58
+ file.write('if not torch.cuda.is_available():\n')
59
+ file.write(' print("CUDA is not available, running on CPU.")\n')
60
+ file.write(' # Adjust logic to run on CPU if necessary\n')
61
 
62
+ from huggingface_hub import login
63
  login(token=os.getenv("TOKEN"))
64
 
65
+ # Step 8: Run the flux_train_ui.py file
66
  run_command([sys.executable, 'flux_train_ui.py'], cwd=repo_dir)
67
 
68
  print("Setup completed successfully.")
69
  else:
70
+ repo_dir = os.path.join(os.getcwd(), 'ai-toolkit')
71
+ flux_train_ui_path = os.path.join(repo_dir, 'flux_train_ui.py')
72
+
73
+ # Ensure Gradio does not try to set share=True
74
+ with open(flux_train_ui_path, 'r') as file:
75
+ lines = file.readlines()
76
 
77
+ with open(flux_train_ui_path, 'w') as file:
78
+ for line in lines:
79
+ # Modify Gradio 'share=True' to 'share=False'
80
+ if 'launch(share=True)' in line:
81
+ line = line.replace('share=True', 'share=False')
82
+ file.write(line)
83
+
84
+ # Modify flux_train_ui.py to handle CUDA availability for torch
85
+ with open(flux_train_ui_path, 'a') as file:
86
+ file.write('\nimport torch\n')
87
+ file.write('if not torch.cuda.is_available():\n')
88
+ file.write(' print("CUDA is not available, running on CPU.")\n')
89
+ file.write(' # Adjust logic to run on CPU if necessary\n')
90
+ from huggingface_hub import login
91
+ login(token=os.getenv("TOKEN"))
92
+
93
  run_command([sys.executable, 'flux_train_ui.py'], cwd=repo_dir)
94
 
95
  print("The 'ai-toolkit' directory already exists. No need to clone.")