dheena commited on
Commit
ea99a27
·
1 Parent(s): f6f293b
Files changed (5) hide show
  1. .space.yaml +1 -0
  2. .streamlit/config.toml +2 -0
  3. Dockerfile +4 -0
  4. src/model.py +3 -1
  5. src/streamlit_app.py +6 -0
.space.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ sdk: docker
.streamlit/config.toml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [browser]
2
+ gatherUsageStats = false
Dockerfile CHANGED
@@ -1,5 +1,7 @@
1
  FROM python:3.9-slim
2
 
 
 
3
  WORKDIR /app
4
 
5
  RUN apt-get update && apt-get install -y \
@@ -15,6 +17,8 @@ COPY src/ ./src/
15
 
16
  RUN pip3 install -r requirements.txt
17
 
 
 
18
  EXPOSE 8501
19
 
20
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
 
1
  FROM python:3.9-slim
2
 
3
+ USER root
4
+
5
  WORKDIR /app
6
 
7
  RUN apt-get update && apt-get install -y \
 
17
 
18
  RUN pip3 install -r requirements.txt
19
 
20
+ ENV STREAMLIT_BROWSER_GATHERUSAGESTATS false
21
+
22
  EXPOSE 8501
23
 
24
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
src/model.py CHANGED
@@ -6,9 +6,11 @@ from PIL import Image
6
  from fastapi import FastAPI
7
  from typing import List
8
  import segmentation
 
 
9
 
10
  device = "cpu"
11
- model, preprocess = clip.load("ViT-B/32", device=device, download_root="./clip_cache")
12
 
13
  def get_image_features(image: Image.Image) -> np.ndarray:
14
  """Extract CLIP features from an image."""
 
6
  from fastapi import FastAPI
7
  from typing import List
8
  import segmentation
9
+ import os
10
+
11
 
12
  device = "cpu"
13
+ model, preprocess = clip.load("ViT-B/32", device=device, download_root=os.getcwd())
14
 
15
  def get_image_features(image: Image.Image) -> np.ndarray:
16
  """Extract CLIP features from an image."""
src/streamlit_app.py CHANGED
@@ -2,6 +2,12 @@ import streamlit as st
2
  from PIL import Image
3
  import model
4
 
 
 
 
 
 
 
5
 
6
  image_url_input = st.text_input("Enter the image URL:")
7
  k_value_input = st.number_input("Enter k_value:", min_value=1, value=5)
 
2
  from PIL import Image
3
  import model
4
 
5
+ import asyncio
6
+ try:
7
+ asyncio.get_running_loop()
8
+ except RuntimeError:
9
+ asyncio.set_event_loop(asyncio.new_event_loop())
10
+
11
 
12
  image_url_input = st.text_input("Enter the image URL:")
13
  k_value_input = st.number_input("Enter k_value:", min_value=1, value=5)