shaheer-data commited on
Commit
7c2fc15
·
verified ·
1 Parent(s): 5b12e1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -3,35 +3,12 @@ import numpy as np
3
  import tensorflow as tf
4
  from tensorflow.keras.models import load_model
5
  from PIL import Image
6
- import requests
7
- import tempfile
8
  import os
9
 
10
- def download_model_from_gdrive():
11
- """Downloads the model from Google Drive."""
12
- gdrive_url = "https://drive.google.com/uc?id=1EnokggrC6ymrSibtj2t7IHWb9QVtrehS"
13
- output_path = "final_meta_model.keras"
14
-
15
- with requests.get(gdrive_url, stream=True) as r:
16
- r.raise_for_status()
17
- with open(output_path, "wb") as f:
18
- for chunk in r.iter_content(chunk_size=8192):
19
- f.write(chunk)
20
-
21
- return output_path
22
-
23
- def load_or_download_model():
24
- """Loads the model from Hugging Face or Google Drive."""
25
- hf_model_path = "final_meta_model.keras"
26
-
27
- # Check if model exists locally (from Hugging Face Space storage)
28
- if os.path.exists(hf_model_path):
29
- model = load_model(hf_model_path)
30
- else:
31
- st.write("Model not found locally. Downloading from Google Drive...")
32
- model_path = download_model_from_gdrive()
33
- model = load_model(model_path)
34
-
35
  return model
36
 
37
  def preprocess_image(image):
@@ -61,7 +38,7 @@ if uploaded_image:
61
 
62
  # Load model
63
  with st.spinner("Loading model..."):
64
- model = load_or_download_model()
65
 
66
  # Preprocess image
67
  image = Image.open(uploaded_image)
 
3
  import tensorflow as tf
4
  from tensorflow.keras.models import load_model
5
  from PIL import Image
 
 
6
  import os
7
 
8
+ def load_model_from_huggingface():
9
+ """Loads the model from Hugging Face Hub."""
10
+ from huggingface_hub import from_pretrained_keras
11
+ model = from_pretrained_keras("shaheer-data/Yellow-Rust-Prediction")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  return model
13
 
14
  def preprocess_image(image):
 
38
 
39
  # Load model
40
  with st.spinner("Loading model..."):
41
+ model = load_model_from_huggingface()
42
 
43
  # Preprocess image
44
  image = Image.open(uploaded_image)