encryptd commited on
Commit
0b8a564
·
verified ·
1 Parent(s): 6699d29

Update app.py

Browse files

Fix Dependencies

Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -1,3 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import spaces
3
  import torch
 
1
+ import os
2
+ import sys
3
+ import subprocess
4
+
5
+ # --- START DEPENDENCY FIX ---
6
+ # This block ensures the correct libraries are loaded even if the build failed.
7
+ def install_dependencies():
8
+ print("Checking dependencies...")
9
+ try:
10
+ # Try to import the specific function that is causing the crash
11
+ from huggingface_hub import is_offline_mode
12
+ except ImportError:
13
+ print("Dependency Mismatch detected. Forcing re-install...")
14
+
15
+ # 1. Force uninstall the broken libraries
16
+ subprocess.run([sys.executable, "-m", "pip", "uninstall", "-y", "huggingface_hub", "transformers"], check=False)
17
+
18
+ # 2. Force install the working versions
19
+ subprocess.run([
20
+ sys.executable, "-m", "pip", "install",
21
+ "huggingface-hub>=0.24.0",
22
+ "git+https://github.com/huggingface/transformers.git",
23
+ "accelerate>=0.26.0"
24
+ ], check=True)
25
+
26
+ print("Dependencies fixed. Restarting app...")
27
+ # 3. Restart the entire script to load the new files
28
+ os.execv(sys.executable, [sys.executable] + sys.argv)
29
+
30
+ install_dependencies()
31
+ # --- END DEPENDENCY FIX ---
32
+
33
  import gradio as gr
34
  import spaces
35
  import torch