Darshan03 commited on
Commit
04c16d3
·
verified ·
1 Parent(s): 41d39e5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +33 -3
src/streamlit_app.py CHANGED
@@ -7,6 +7,7 @@ from pathlib import Path
7
  from tensorflow.keras.applications import ConvNeXtLarge
8
  import streamlit as st
9
  import io
 
10
 
11
  def setup_logging():
12
  logging.basicConfig(
@@ -14,6 +15,32 @@ def setup_logging():
14
  format='%(asctime)s - %(levelname)s - %(message)s'
15
  )
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def create_convnext_model(input_shape=(512, 512, 3)):
18
  base_model = ConvNeXtLarge(
19
  include_top=False,
@@ -120,10 +147,13 @@ def main():
120
  base_dir = Path(__file__).parent.absolute()
121
  model_path = base_dir / 'model.h5'
122
 
123
- # Check if model exists
124
  if not model_path.exists():
125
- st.error(f"Model not found at {model_path}")
126
- return
 
 
 
127
 
128
  # Load the model
129
  try:
 
7
  from tensorflow.keras.applications import ConvNeXtLarge
8
  import streamlit as st
9
  import io
10
+ from huggingface_hub import hf_hub_download
11
 
12
  def setup_logging():
13
  logging.basicConfig(
 
15
  format='%(asctime)s - %(levelname)s - %(message)s'
16
  )
17
 
18
+ def download_model_from_hub():
19
+ try:
20
+ st.info("Model not found locally. Downloading from Hugging Face Hub...")
21
+
22
+ # Configuration for Hugging Face Hub
23
+ repo_id = "Darshan03/convnext_volcano_detector"
24
+ filename_in_repo = "model.h5"
25
+ local_download_dir = "models"
26
+
27
+ # Create models directory if it doesn't exist
28
+ Path(local_download_dir).mkdir(parents=True, exist_ok=True)
29
+
30
+ # Download the model
31
+ local_model_path = hf_hub_download(
32
+ repo_id=repo_id,
33
+ filename=filename_in_repo,
34
+ cache_dir=local_download_dir
35
+ )
36
+
37
+ st.success(f"Model downloaded successfully to: {local_model_path}")
38
+ return local_model_path
39
+
40
+ except Exception as e:
41
+ st.error(f"Error downloading model from Hugging Face Hub: {str(e)}")
42
+ raise
43
+
44
  def create_convnext_model(input_shape=(512, 512, 3)):
45
  base_model = ConvNeXtLarge(
46
  include_top=False,
 
147
  base_dir = Path(__file__).parent.absolute()
148
  model_path = base_dir / 'model.h5'
149
 
150
+ # Check if model exists, if not download from Hugging Face Hub
151
  if not model_path.exists():
152
+ try:
153
+ model_path = download_model_from_hub()
154
+ except Exception as e:
155
+ st.error("Failed to download model. Please check your internet connection and try again.")
156
+ return
157
 
158
  # Load the model
159
  try: