Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,28 @@
|
|
1 |
-
import
|
|
|
2 |
import tensorflow as tf
|
3 |
-
import numpy as np
|
4 |
-
from tensorflow.keras.utils import load_img, img_to_array
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
predicted_label = class_labels[np.argmax(prediction)]
|
18 |
-
return predicted_label
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
)
|
28 |
|
29 |
-
#
|
30 |
-
if __name__ == "__main__":
|
31 |
-
iface.launch()
|
|
|
1 |
+
import requests
|
2 |
+
import tempfile
|
3 |
import tensorflow as tf
|
|
|
|
|
4 |
|
5 |
+
# URL to the model file in your Hugging Face repository
|
6 |
+
url = 'https://huggingface.co/datasets/yolac/BacterialMorphologyClassification'
|
7 |
+
# Download the model file
|
8 |
+
response = requests.get(url, stream=True)
|
9 |
|
10 |
+
# Check if the download was successful
|
11 |
+
if response.status_code == 200:
|
12 |
+
# Create a temporary file to save the model
|
13 |
+
with tempfile.NamedTemporaryFile(suffix=".h5", delete=False) as temp_file:
|
14 |
+
for chunk in response.iter_content(chunk_size=8192):
|
15 |
+
if chunk:
|
16 |
+
temp_file.write(chunk)
|
17 |
+
temp_file_path = temp_file.name # Get the path to the temporary file
|
|
|
|
|
18 |
|
19 |
+
# Load the pre-trained model
|
20 |
+
try:
|
21 |
+
model = tf.keras.models.load_model(temp_file_path)
|
22 |
+
print("Model loaded successfully.")
|
23 |
+
except OSError as e:
|
24 |
+
print(f"Error loading the model: {e}")
|
25 |
+
else:
|
26 |
+
print("Failed to download the model. Status code:", response.status_code)
|
27 |
|
28 |
+
# Now you can use the `model` object for predictions or further processing.
|
|
|
|