-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_load.py
More file actions
36 lines (27 loc) · 1.19 KB
/
Copy pathmodel_load.py
File metadata and controls
36 lines (27 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import tensorflow as tf
from pathlib import Path
from google.cloud import storage
model_dir = "model"
model_filename = "final_model_mm_v9_20.h5"
model_path = os.path.join(model_dir, model_filename)
prod = os.environ.get('PRODUCTION', "False").lower() == "true"
if not os.path.exists(model_path):
os.makedirs(model_dir, exist_ok=True)
cloud_storage_url = "https://storage.cloud.google.com/hijaiyah_model/final_model_mm_v9_20.h5"
if prod:
client = storage.Client()
else:
client = storage.Client.from_service_account_json(Path('venv/serviceAccount.json').resolve())
bucket = client.bucket("hijaiyah_model")
blob = bucket.blob(model_filename)
blob.download_to_filename(model_path)
print(f"Model downloaded to {model_path}")
else:
print(f"Model already exists at {model_path}, loading without download.")
model = tf.keras.models.load_model(model_path)
class_names = [ 'ain', 'alif', 'ba', 'dal', 'dhod', 'dzal',
'dzho', 'fa', 'ghoin', 'ha', 'ha\'', 'hamzah', 'jim',
'kaf', 'kho', 'lam', 'lamalif', 'mim', 'nun', 'qof',
'ro', 'shod', 'sin', 'syin', 'ta', 'tho', 'tsa',
'wawu', 'ya', 'zain']