Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,30 @@
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
| 3 |
|
| 4 |
-
# Function to install
|
| 5 |
def install(package):
|
| 6 |
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
| 7 |
|
| 8 |
-
# Ensure NumPy
|
| 9 |
try:
|
| 10 |
import numpy as np
|
| 11 |
-
if not np.__version__.startswith("1."):
|
| 12 |
-
print(f"Detected NumPy version {np.__version__}. Downgrading to
|
| 13 |
-
install("numpy
|
| 14 |
except ImportError:
|
| 15 |
-
print("NumPy not found. Installing NumPy 1.
|
| 16 |
-
install("numpy
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
import torch
|
| 21 |
except ImportError:
|
|
@@ -27,15 +36,7 @@ try:
|
|
| 27 |
except ImportError:
|
| 28 |
install("Pillow==9.5.0")
|
| 29 |
|
| 30 |
-
# Import
|
| 31 |
-
import torch
|
| 32 |
-
import torch.nn as nn
|
| 33 |
-
import torch.nn.functional as F
|
| 34 |
-
import torchvision.transforms as transforms
|
| 35 |
-
from PIL import Image
|
| 36 |
-
import gradio as gr
|
| 37 |
-
|
| 38 |
-
# Import necessary libraries
|
| 39 |
import torch
|
| 40 |
import torch.nn as nn
|
| 41 |
import torch.nn.functional as F
|
|
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
| 3 |
|
| 4 |
+
# Function to install specific package versions
|
| 5 |
def install(package):
|
| 6 |
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
| 7 |
|
| 8 |
+
# Ensure NumPy and pandas versions are compatible
|
| 9 |
try:
|
| 10 |
import numpy as np
|
| 11 |
+
if not np.__version__.startswith("1.23"):
|
| 12 |
+
print(f"Detected incompatible NumPy version {np.__version__}. Downgrading to 1.23.5...")
|
| 13 |
+
install("numpy==1.23.5")
|
| 14 |
except ImportError:
|
| 15 |
+
print("NumPy not found. Installing NumPy 1.23.5...")
|
| 16 |
+
install("numpy==1.23.5")
|
| 17 |
|
| 18 |
+
try:
|
| 19 |
+
import pandas as pd
|
| 20 |
+
if not pd.__version__.startswith("1.5"):
|
| 21 |
+
print(f"Detected incompatible pandas version {pd.__version__}. Downgrading to 1.5.3...")
|
| 22 |
+
install("pandas==1.5.3")
|
| 23 |
+
except ImportError:
|
| 24 |
+
print("pandas not found. Installing pandas 1.5.3...")
|
| 25 |
+
install("pandas==1.5.3")
|
| 26 |
+
|
| 27 |
+
# Ensure other dependencies are installed
|
| 28 |
try:
|
| 29 |
import torch
|
| 30 |
except ImportError:
|
|
|
|
| 36 |
except ImportError:
|
| 37 |
install("Pillow==9.5.0")
|
| 38 |
|
| 39 |
+
# Import libraries after ensuring installations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
import torch
|
| 41 |
import torch.nn as nn
|
| 42 |
import torch.nn.functional as F
|