traopia commited on
Commit
58b25bf
·
1 Parent(s): cf0b712

update app

Browse files
Files changed (1) hide show
  1. app.py +35 -7
app.py CHANGED
@@ -17,14 +17,36 @@ def load_data_hf():
17
  npy_url = "https://huggingface.co/datasets/traopia/vogue_runway_small/resolve/main/VogueRunway_image.npy"
18
  response = requests.get(npy_url)
19
  response.raise_for_status() # Raise error if download fails
20
- embeddings = np.load(BytesIO(response.content), mmap_mode="r")
21
 
22
  return df, embeddings
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  df, embeddings = load_data_hf()
25
 
26
  # Filter and search
27
- def filter_and_search(fashion_house, category, season, year_range, query):
28
  filtered = df.copy()
29
 
30
  if fashion_house:
@@ -33,7 +55,7 @@ def filter_and_search(fashion_house, category, season, year_range, query):
33
  filtered = filtered[filtered['category'].isin(category)]
34
  if season:
35
  filtered = filtered[filtered['season'].isin(season)]
36
- filtered = filtered[(filtered['year'] >= year_range[0]) & (filtered['year'] <= year_range[1])]
37
 
38
  if query:
39
  results = search_images_by_text(query, filtered, embeddings)
@@ -68,14 +90,20 @@ with gr.Blocks() as demo:
68
  fashion_house = gr.Dropdown(label="Fashion House", choices=sorted(df["designer"].dropna().unique()), multiselect=True)
69
  category = gr.Dropdown(label="Category", choices=sorted(df["category"].dropna().unique()), multiselect=True)
70
  season = gr.Dropdown(label="Season", choices=sorted(df["season"].dropna().unique()), multiselect=True)
71
- year_range = gr.Slider(label="Year Range", minimum=int(df['year'].min()), maximum=int(df['year'].max()), value=(2000, 2025), step=1)
 
 
 
 
 
 
72
 
73
  query = gr.Textbox(label="Search", placeholder="e.g., pink dress")
74
  search_button = gr.Button("Search")
75
 
76
- result_gallery = gr.Gallery(label="Search Results").style(grid=[5], height="auto")
77
  metadata_output = gr.Markdown()
78
- similar_gallery = gr.Gallery(label="Similar Images").style(grid=[5], height="auto")
79
 
80
  metadata_state = gr.State([])
81
  selected_idx = gr.Number(value=0, visible=False)
@@ -86,7 +114,7 @@ with gr.Blocks() as demo:
86
 
87
  search_button.click(
88
  handle_search,
89
- inputs=[fashion_house, category, season, year_range, query],
90
  outputs=[result_gallery, metadata_state, metadata_output, similar_gallery]
91
  )
92
 
 
17
  npy_url = "https://huggingface.co/datasets/traopia/vogue_runway_small/resolve/main/VogueRunway_image.npy"
18
  response = requests.get(npy_url)
19
  response.raise_for_status() # Raise error if download fails
20
+ embeddings = np.load(BytesIO(response.content))
21
 
22
  return df, embeddings
23
 
24
+
25
+ from huggingface_hub import hf_hub_download
26
+ def load_data1():
27
+ # Login using e.g. `huggingface-cli login` to access this dataset
28
+ path = hf_hub_download(
29
+ repo_id="traopia/fashion_show_data_all_embeddings",
30
+ filename="fashion_show_data_all_embeddings.json"
31
+ )
32
+ df = pd.read_json(path, lines = True)
33
+
34
+ #df = pd.read_json("hf://datasets/traopia/fashion_show_data_all_embeddings.json/fashion_show_data_all_embeddings.json", lines=True)
35
+ df["fashion_clip_image"] = df["fashion_clip_image"].apply(lambda x: x[0] if isinstance(x, list) else x)
36
+ df["image_urls"] = df["image_urls"].apply(lambda x: x[0] if x is not None else None)
37
+ df = df.rename(columns={"fashion_house":"designer", "image_urls":"url", "URL":"collection"})
38
+
39
+ df = df.dropna(subset="fashion_clip_image")
40
+ df = df.reset_index(drop=True)
41
+ df["key"] = df.index
42
+ embeddings = np.vstack(df["fashion_clip_image"].values)
43
+
44
+ return df, embeddings
45
+
46
  df, embeddings = load_data_hf()
47
 
48
  # Filter and search
49
+ def filter_and_search(fashion_house, category, season, start_year, end_year, query):
50
  filtered = df.copy()
51
 
52
  if fashion_house:
 
55
  filtered = filtered[filtered['category'].isin(category)]
56
  if season:
57
  filtered = filtered[filtered['season'].isin(season)]
58
+ filtered = filtered[(filtered['year'] >= start_year) & (filtered['year'] <= end_year)]
59
 
60
  if query:
61
  results = search_images_by_text(query, filtered, embeddings)
 
90
  fashion_house = gr.Dropdown(label="Fashion House", choices=sorted(df["designer"].dropna().unique()), multiselect=True)
91
  category = gr.Dropdown(label="Category", choices=sorted(df["category"].dropna().unique()), multiselect=True)
92
  season = gr.Dropdown(label="Season", choices=sorted(df["season"].dropna().unique()), multiselect=True)
93
+ #year_range = gr.RangeSlider(label="Year Range", minimum=int(df['year'].min()), maximum=int(df['year'].max()), value=(2000, 2025), step=1)
94
+
95
+ min_year = int(df['year'].min())
96
+ max_year = int(df['year'].max())
97
+
98
+ start_year = gr.Slider(label="Start Year", minimum=min_year, maximum=max_year, value=2000, step=1)
99
+ end_year = gr.Slider(label="End Year", minimum=min_year, maximum=max_year, value=2025, step=1)
100
 
101
  query = gr.Textbox(label="Search", placeholder="e.g., pink dress")
102
  search_button = gr.Button("Search")
103
 
104
+ result_gallery = gr.Gallery(label="Search Results", columns=5, height="auto")
105
  metadata_output = gr.Markdown()
106
+ similar_gallery = gr.Gallery(label="Similar Images", columns = 5, height="auto")
107
 
108
  metadata_state = gr.State([])
109
  selected_idx = gr.Number(value=0, visible=False)
 
114
 
115
  search_button.click(
116
  handle_search,
117
+ inputs=[fashion_house, category, season, start_year, end_year, query],
118
  outputs=[result_gallery, metadata_state, metadata_output, similar_gallery]
119
  )
120