Spaces:
Sleeping
Sleeping
add deprecated gradio class
Browse files- README.md +1 -1
- app.py +3 -2
- utils/old_gradio_class.py +19 -0
README.md
CHANGED
@@ -6,7 +6,7 @@ colorTo: "indigo" # The ending color of the gradient in your Space thu
|
|
6 |
sdk: "gradio" # The SDK you're using (gradio/streamlit/docker/static)
|
7 |
sdk_version: "2.8.9" # The version of the SDK
|
8 |
app_file: "app.py" # The file that contains your app. Make sure the path is correct.
|
9 |
-
python_version: "3.11" # Specify the python version, default is 3.10
|
10 |
pinned: false # Whether your Space stays pinned on your profile
|
11 |
lisence: mit
|
12 |
---
|
|
|
6 |
sdk: "gradio" # The SDK you're using (gradio/streamlit/docker/static)
|
7 |
sdk_version: "2.8.9" # The version of the SDK
|
8 |
app_file: "app.py" # The file that contains your app. Make sure the path is correct.
|
9 |
+
python_version: "3.11.9" # Specify the python version, default is 3.10
|
10 |
pinned: false # Whether your Space stays pinned on your profile
|
11 |
lisence: mit
|
12 |
---
|
app.py
CHANGED
@@ -14,6 +14,7 @@ from plots import get_pre_define_colors
|
|
14 |
from utils.load_model import load_xclip
|
15 |
from utils.predict import xclip_pred
|
16 |
|
|
|
17 |
|
18 |
DEVICE = "cpu"
|
19 |
XCLIP, OWLVIT_PRECESSOR = load_xclip(DEVICE)
|
@@ -21,7 +22,7 @@ XCLIP_DESC_PATH = "data/jsons/bs_cub_desc.json"
|
|
21 |
XCLIP_DESC = json.load(open(XCLIP_DESC_PATH, "r"))
|
22 |
PREPROCESS = lambda x: OWLVIT_PRECESSOR(images=x, return_tensors='pt')
|
23 |
IMAGES_FOLDER = "data/images"
|
24 |
-
|
25 |
# correct_predictions = [k for k, v in XCLIP_RESULTS.items() if v['prediction']]
|
26 |
|
27 |
# get the intersection of sachit and xclip (revised)
|
@@ -206,7 +207,7 @@ blank_image = np.array(Image.open('data/images/final.png').convert('RGB'))
|
|
206 |
PART_IMAGES_DICT = {file_name: load_part_images(file_name) for file_name in IMAGE_FILE_LIST}
|
207 |
|
208 |
# --- Gradio Functions ---
|
209 |
-
def update_selected_image(event:
|
210 |
image_height = 400
|
211 |
index = event.index
|
212 |
|
|
|
14 |
from utils.load_model import load_xclip
|
15 |
from utils.predict import xclip_pred
|
16 |
|
17 |
+
from utils.old_gradio_class import SelectData
|
18 |
|
19 |
DEVICE = "cpu"
|
20 |
XCLIP, OWLVIT_PRECESSOR = load_xclip(DEVICE)
|
|
|
22 |
XCLIP_DESC = json.load(open(XCLIP_DESC_PATH, "r"))
|
23 |
PREPROCESS = lambda x: OWLVIT_PRECESSOR(images=x, return_tensors='pt')
|
24 |
IMAGES_FOLDER = "data/images"
|
25 |
+
XCLIP_RESULTS = json.load(open("data/jsons/xclip_org.json", "r"))
|
26 |
# correct_predictions = [k for k, v in XCLIP_RESULTS.items() if v['prediction']]
|
27 |
|
28 |
# get the intersection of sachit and xclip (revised)
|
|
|
207 |
PART_IMAGES_DICT = {file_name: load_part_images(file_name) for file_name in IMAGE_FILE_LIST}
|
208 |
|
209 |
# --- Gradio Functions ---
|
210 |
+
def update_selected_image(event: SelectData):
|
211 |
image_height = 400
|
212 |
index = event.index
|
213 |
|
utils/old_gradio_class.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio.helpers import EventData
|
2 |
+
from gradio.blocks import Block
|
3 |
+
from typing import Any
|
4 |
+
|
5 |
+
class SelectData(EventData):
|
6 |
+
def __init__(self, target: Block | None, data: Any):
|
7 |
+
super().__init__(target, data)
|
8 |
+
self.index: int | tuple[int, int] = data["index"]
|
9 |
+
"""
|
10 |
+
The index of the selected item. Is a tuple if the component is two dimensional or selection is a range.
|
11 |
+
"""
|
12 |
+
self.value: Any = data["value"]
|
13 |
+
"""
|
14 |
+
The value of the selected item.
|
15 |
+
"""
|
16 |
+
self.selected: bool = data.get("selected", True)
|
17 |
+
"""
|
18 |
+
True if the item was selected, False if deselected.
|
19 |
+
"""
|