E-Adam commited on
Commit
6863bf0
·
verified ·
1 Parent(s): 74d207b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -23
app.py CHANGED
@@ -9,35 +9,41 @@ os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
9
  import gradio as gr
10
  import numpy as np
11
 
12
- def setup_tensorflow():
13
- try:
14
- import tensorflow as tf
15
- print(f"TensorFlow {tf.__version__} déjà disponible")
16
- return tf
17
- except ImportError:
18
- print("Installation de TensorFlow...")
 
 
 
 
 
 
 
 
19
  try:
20
- # Installation spécifique pour environnement Gradio
21
  subprocess.check_call([
22
  sys.executable, "-m", "pip", "install",
23
- "tensorflow-cpu==2.13.0",
24
- "--no-deps", "--force-reinstall", "--quiet"
25
  ])
26
-
27
- # Clear import cache
28
- if 'tensorflow' in sys.modules:
29
- del sys.modules['tensorflow']
30
-
31
- import tensorflow as tf
32
- print(f"TensorFlow {tf.__version__} installé avec succès")
33
- return tf
34
-
35
  except Exception as e:
36
- print(f"Erreur d'installation: {e}")
37
- return None
 
 
 
 
 
 
 
 
 
 
38
 
39
- # Usage dans votre app Gradio
40
- tf = setup_tensorflow()
41
  if tf is not None:
42
  from tensorflow.keras.models import Sequential
43
  from tensorflow.keras.layers import Embedding, GRU, Dense
 
9
  import gradio as gr
10
  import numpy as np
11
 
12
+ L'erreur No module named 'absl' indique que les dépendances de TensorFlow ne sont pas correctement installées. Voici les solutions :
13
+ Solution 1: Installation des dépendances d'abord
14
+ pythonimport sys
15
+ import subprocess
16
+
17
+ def install_tensorflow_with_deps():
18
+ packages_to_install = [
19
+ "absl-py",
20
+ "six",
21
+ "numpy",
22
+ "protobuf",
23
+ "tensorflow-cpu==2.13.0"
24
+ ]
25
+
26
+ for package in packages_to_install:
27
  try:
28
+ print(f"Installation de {package}...")
29
  subprocess.check_call([
30
  sys.executable, "-m", "pip", "install",
31
+ package, "--quiet", "--no-warn-script-location"
 
32
  ])
 
 
 
 
 
 
 
 
 
33
  except Exception as e:
34
+ print(f"Erreur avec {package}: {e}")
35
+
36
+ try:
37
+ import tensorflow as tf
38
+ print(f"✓ TensorFlow {tf.__version__} prêt")
39
+ return tf
40
+ except Exception as e:
41
+ print(f"✗ Erreur finale: {e}")
42
+ return None
43
+
44
+ # Usage
45
+ tf = install_tensorflow_with_deps()
46
 
 
 
47
  if tf is not None:
48
  from tensorflow.keras.models import Sequential
49
  from tensorflow.keras.layers import Embedding, GRU, Dense