Sanket17 commited on
Commit
2fc40df
·
verified ·
1 Parent(s): 0d06a7b

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +35 -0
main.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gdown
3
+ from pathlib import Path
4
+ from fastapi import FastAPI
5
+
6
+ app = FastAPI()
7
+
8
+ def download_weights():
9
+ # Create directories if they don't exist
10
+ Path("weights/icon_detect").mkdir(parents=True, exist_ok=True)
11
+ Path("weights/icon_caption_florence").mkdir(parents=True, exist_ok=True)
12
+
13
+ # Correct file mapping with Drive file IDs and their corresponding local paths
14
+ files_to_download = {
15
+ "1hUCqZ3X8mcM-KcwWFjcsFg7PA0hUvE3k": "weights/icon_caption_florence/model.safetensors",
16
+ "1p-Y7rd0FfjNnv_jewCi7ZjXH3T-qtyAa": "weights/icon_detect/best.pt"
17
+ }
18
+
19
+ for file_id, output_path in files_to_download.items():
20
+ if not os.path.exists(output_path):
21
+ print(f"Downloading {output_path}...")
22
+ url = f"https://drive.google.com/uc?id={file_id}"
23
+ gdown.download(url, output_path, quiet=False)
24
+ print(f"Downloaded {output_path}")
25
+ else:
26
+ print(f"File {output_path} already exists, skipping download")
27
+
28
+ @app.on_event("startup")
29
+ def startup_event():
30
+ print("FastAPI app is starting, checking and downloading weights if necessary...")
31
+ download_weights()
32
+
33
+ @app.get("/")
34
+ def root():
35
+ return {"message": "FastAPI app is running and weights are ready!"}