Spaces:
Sleeping
Sleeping
| import os | |
| from tensorflow.keras.models import load_model | |
| #def load_trained_model(path): | |
| #return load_model(path) | |
| # ✅ Set writable cache directory | |
| os.environ["HF_HUB_CACHE"] = "/tmp/huggingface" | |
| def run_prediction(model, processed_frame): # Renamed function | |
| prediction = model.predict(processed_frame) | |
| return prediction[0][0] | |
| ''' | |
| import os | |
| import urllib.request | |
| from tensorflow.keras.models import load_model | |
| def load_trained_model(path="violence_model.h5"): | |
| url = "https://huggingface.co/spaces/muskan19/Violence_Detector/blob/main/violence_model.keras" | |
| if not os.path.exists(path): | |
| print("Downloading model...") | |
| urllib.request.urlretrieve(url, path) | |
| print("Download complete.") | |
| return load_model(path, compile=False) | |
| ''' | |
| ''' | |
| import os | |
| import urllib.request | |
| from tensorflow.keras.models import load_model | |
| def load_trained_model(path="violence_model.keras"): | |
| url = "https://huggingface.co/spaces/muskan19/Violence_Detector/resolve/main/violence_model.keras" | |
| if not os.path.exists(path): | |
| print("Downloading model...") | |
| urllib.request.urlretrieve(url, path) | |
| print("Download complete.") | |
| return load_model(path, compile=False) | |
| ''' | |
| ''' | |
| from huggingface_hub import hf_hub_download | |
| from tensorflow.keras.models import load_model | |
| def load_trained_model(): | |
| model_path = hf_hub_download( | |
| repo_id="muskan19/Violence_Detector", | |
| filename="violence_model.keras" | |
| ) | |
| return load_model(model_path, compile=False) | |
| ''' | |
| ''' | |
| import os | |
| import urllib.request | |
| from tensorflow.keras.models import load_model | |
| def load_trained_model(path="violence_model.keras"): | |
| url = "https://huggingface.co/spaces/muskan19/Violence_Detector/resolve/main/violence_model.keras" | |
| if not os.path.exists(path): | |
| print("📥 Downloading model...") | |
| urllib.request.urlretrieve(url, path) | |
| return load_model(path, compile=False) | |
| ''' | |
| from huggingface_hub import hf_hub_download | |
| from tensorflow.keras.models import load_model | |
| def load_trained_model(): | |
| model_path = hf_hub_download( | |
| repo_id="muskan19/violence_model", # Your model repo, NOT Space | |
| filename="violence_model.h5" # Exact file name | |
| ) | |
| return load_model(model_path, compile=False) | |