Spaces:
Sleeping
Sleeping
Update Google Drive file ID
Browse files
app.py
CHANGED
@@ -1,22 +1,40 @@
|
|
1 |
import sys
|
2 |
from pathlib import Path
|
3 |
-
|
4 |
import os
|
5 |
import gdown
|
|
|
6 |
|
7 |
MODEL_PATH = "models/saved/final_model.pt"
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Add src directory to Python path
|
15 |
src_path = Path(__file__).parent / "src"
|
16 |
sys.path.append(str(src_path))
|
17 |
|
18 |
-
# Import and run the main app
|
19 |
-
from src.app import main
|
20 |
-
|
21 |
if __name__ == "__main__":
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import sys
|
2 |
from pathlib import Path
|
|
|
3 |
import os
|
4 |
import gdown
|
5 |
+
import streamlit as st
|
6 |
|
7 |
MODEL_PATH = "models/saved/final_model.pt"
|
8 |
+
# You need to replace this with the direct download link of your model file
|
9 |
+
# To get the direct link: Right-click your model file in Google Drive -> Get link -> Make sure it's set to "Anyone with the link can view"
|
10 |
+
# Then replace the file ID in the URL below
|
11 |
+
GOOGLE_DRIVE_FILE_ID = "1xhYKuC5_Yri3mm3Ejt-SpB2WAVUTJvc_" # Replace with your actual file ID
|
12 |
+
GOOGLE_DRIVE_URL = f"https://drive.google.com/uc?id={GOOGLE_DRIVE_FILE_ID}"
|
13 |
|
14 |
+
@st.cache_resource
|
15 |
+
def download_model():
|
16 |
+
"""Download model from Google Drive if not exists."""
|
17 |
+
if not os.path.exists(MODEL_PATH):
|
18 |
+
os.makedirs(os.path.dirname(MODEL_PATH), exist_ok=True)
|
19 |
+
with st.spinner("Downloading model from Google Drive..."):
|
20 |
+
try:
|
21 |
+
gdown.download(GOOGLE_DRIVE_URL, MODEL_PATH, quiet=False)
|
22 |
+
st.success("Model downloaded successfully!")
|
23 |
+
except Exception as e:
|
24 |
+
st.error(f"Failed to download model: {str(e)}")
|
25 |
+
st.error("Please check your Google Drive link and make sure the file is publicly accessible.")
|
26 |
+
return False
|
27 |
+
return True
|
28 |
|
29 |
# Add src directory to Python path
|
30 |
src_path = Path(__file__).parent / "src"
|
31 |
sys.path.append(str(src_path))
|
32 |
|
|
|
|
|
|
|
33 |
if __name__ == "__main__":
|
34 |
+
# Download model first
|
35 |
+
if download_model():
|
36 |
+
# Import and run the main app
|
37 |
+
from src.app import main
|
38 |
+
main()
|
39 |
+
else:
|
40 |
+
st.error("Cannot start the application without the model file.")
|