huntjosh commited on
Commit
2f82ea0
·
1 Parent(s): 0943f7f
Files changed (2) hide show
  1. app.py +37 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import streamlit as st
3
+ import requests
4
+ from pathlib import Path
5
+
6
+ # Define model path and URL
7
+ MODEL_PATH = "pytorch_model.pth"
8
+ MODEL_URL = "https://huggingface.co/zongzhuofan/co-detr-vit-large-coco/resolve/main/pytorch_model.pth"
9
+
10
+ # Download model if not exists
11
+ @st.cache_resource
12
+ def download_model():
13
+ if not Path(MODEL_PATH).exists():
14
+ with st.spinner("Downloading model... This might take a few minutes..."):
15
+ response = requests.get(MODEL_URL, stream=True)
16
+ with open(MODEL_PATH, "wb") as f:
17
+ for chunk in response.iter_content(chunk_size=8192):
18
+ if chunk:
19
+ f.write(chunk)
20
+ return MODEL_PATH
21
+
22
+ # Load the model
23
+ model = YourModelClass()
24
+ model_path = download_model()
25
+ model.load_state_dict(torch.load(model_path, map_location='cpu'))
26
+ model.eval()
27
+
28
+ st.title("Co-DETR Model")
29
+
30
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png"])
31
+ if uploaded_file is not None:
32
+ # Preprocess the image
33
+ input_data = preprocess_image(uploaded_file)
34
+ with torch.no_grad():
35
+ output = model(input_data)
36
+ # Postprocess output if necessary
37
+ st.write("Output:", output)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ requests
3
+ torch