Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import subprocess
|
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
import re # Import the regular expression module
|
| 5 |
-
|
| 6 |
|
| 7 |
def install_tensorflow():
|
| 8 |
"""
|
|
@@ -14,13 +14,15 @@ def install_tensorflow():
|
|
| 14 |
# Use sys.executable to ensure we're using the correct pip for the current Python interpreter
|
| 15 |
result = subprocess.run(
|
| 16 |
[sys.executable, "-m", "pip", "install", "tensorflow"],
|
| 17 |
-
check=
|
| 18 |
stdout=subprocess.PIPE,
|
| 19 |
stderr=subprocess.PIPE,
|
| 20 |
text=True,
|
| 21 |
)
|
| 22 |
-
print("
|
| 23 |
-
print(result.stdout)
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Check for successful installation using regex
|
| 26 |
if re.search(r"Successfully installed tensorflow", result.stdout):
|
|
@@ -33,14 +35,6 @@ def install_tensorflow():
|
|
| 33 |
)
|
| 34 |
return False
|
| 35 |
|
| 36 |
-
except subprocess.CalledProcessError as e:
|
| 37 |
-
print(f"Error installing TensorFlow: {e}")
|
| 38 |
-
print(f"Error output (stderr):\n{e.stderr}")
|
| 39 |
-
print("Please check your pip installation, internet connection, and any system dependencies.")
|
| 40 |
-
print("You may need to install TensorFlow manually. Instructions can be found at:")
|
| 41 |
-
print("https://www.tensorflow.org/install")
|
| 42 |
-
return False # Indicate installation failure
|
| 43 |
-
|
| 44 |
except Exception as ex:
|
| 45 |
print(f"An unexpected error occurred during TensorFlow installation: {ex}")
|
| 46 |
return False # Indicate installation failure
|
|
@@ -372,4 +366,3 @@ except KeyboardInterrupt:
|
|
| 372 |
except Exception as e:
|
| 373 |
print(f"An error occurred during training: {e}")
|
| 374 |
print("Please check your data and model configuration.")
|
| 375 |
-
|
|
|
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
import re # Import the regular expression module
|
| 5 |
+
import shutil # Import the shutil module
|
| 6 |
|
| 7 |
def install_tensorflow():
|
| 8 |
"""
|
|
|
|
| 14 |
# Use sys.executable to ensure we're using the correct pip for the current Python interpreter
|
| 15 |
result = subprocess.run(
|
| 16 |
[sys.executable, "-m", "pip", "install", "tensorflow"],
|
| 17 |
+
check=False, # Do NOT use check=True here. We'll handle errors ourselves.
|
| 18 |
stdout=subprocess.PIPE,
|
| 19 |
stderr=subprocess.PIPE,
|
| 20 |
text=True,
|
| 21 |
)
|
| 22 |
+
print("pip install output (stdout):")
|
| 23 |
+
print(result.stdout)
|
| 24 |
+
print("pip install error output (stderr):")
|
| 25 |
+
print(result.stderr)
|
| 26 |
|
| 27 |
# Check for successful installation using regex
|
| 28 |
if re.search(r"Successfully installed tensorflow", result.stdout):
|
|
|
|
| 35 |
)
|
| 36 |
return False
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
except Exception as ex:
|
| 39 |
print(f"An unexpected error occurred during TensorFlow installation: {ex}")
|
| 40 |
return False # Indicate installation failure
|
|
|
|
| 366 |
except Exception as e:
|
| 367 |
print(f"An error occurred during training: {e}")
|
| 368 |
print("Please check your data and model configuration.")
|
|
|