mhamilton723 commited on
Commit
534fa09
1 Parent(s): 2275a39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -2
app.py CHANGED
@@ -1,4 +1,45 @@
1
  import streamlit as st
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import torch
3
+ import torchvision.transforms as T
4
+ from PIL import Image
5
 
6
+ # Assuming the necessary packages (featup, clip, etc.) are installed and accessible
7
+ from featup.util import norm, unnorm
8
+ from featup.plotting import plot_feats
9
+
10
+ # Setup - ensure the repository content is accessible in the environment
11
+
12
+ # Streamlit UI
13
+ st.title("Feature Upsampling Demo")
14
+
15
+ # File uploader
16
+ uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
17
+ if uploaded_file is not None:
18
+ image = Image.open(uploaded_file).convert("RGB")
19
+
20
+ # Image preprocessing
21
+ input_size = 224
22
+ transform = T.Compose([
23
+ T.Resize(input_size),
24
+ T.CenterCrop((input_size, input_size)),
25
+ T.ToTensor(),
26
+ norm
27
+ ])
28
+
29
+ image_tensor = transform(image).unsqueeze(0) # Assuming CUDA is available, .cuda()
30
+
31
+ # Model selection
32
+ model_option = st.selectbox(
33
+ 'Choose a model for feature upsampling',
34
+ ('dino16', 'dinov2', 'clip', 'resnet50')
35
+ )
36
+
37
+ if st.button('Upsample Features'):
38
+ # Load the selected model
39
+ upsampler = torch.hub.load("mhamilton723/FeatUp", model_option).cuda()
40
+ hr_feats = upsampler(image_tensor)
41
+ lr_feats = upsampler.model(image_tensor)
42
+
43
+ # Plotting - adjust the plot_feats function or find an alternative to display images in Streamlit
44
+ # This step will likely need customization to display within Streamlit's interface
45
+ plot_feats(unnorm(image_tensor)[0], lr_feats[0], hr_feats[0])