leedoming commited on
Commit
4737554
·
verified ·
1 Parent(s): dfc8c96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -103,9 +103,8 @@ def segment_image(image_path, client):
103
  # 원본 이미지를 다시 읽어 반환
104
  return Image.open(image_path)
105
 
106
- # Process database with segmentation
107
  @st.cache_data
108
- def process_database(client):
109
  database_embeddings = []
110
  database_info = []
111
  for item in data:
@@ -120,10 +119,6 @@ def process_database(client):
120
  temp_path = f"temp_{product_id}.jpg"
121
  image.save(temp_path, 'JPEG')
122
 
123
- segmented_image = segment_image(temp_path, client)
124
- embedding = get_image_embedding(segmented_image)
125
-
126
- database_embeddings.append(embedding)
127
  database_info.append({
128
  'id': product_id,
129
  'category': item['카테고리'],
@@ -131,9 +126,21 @@ def process_database(client):
131
  'name': item['제품명'],
132
  'price': item['정가'],
133
  'discount': item['할인율'],
134
- 'image_url': image_url
 
135
  })
136
 
 
 
 
 
 
 
 
 
 
 
 
137
  return np.vstack(database_embeddings), database_info
138
 
139
  # Streamlit app
@@ -146,7 +153,7 @@ if api_key:
146
  CLIENT = setup_roboflow_client(api_key)
147
 
148
  # Initialize database_embeddings and database_info
149
- database_embeddings, database_info = process_database(CLIENT)
150
 
151
  uploaded_file = st.file_uploader("Choose an image...", type="jpg")
152
  if uploaded_file is not None:
 
103
  # 원본 이미지를 다시 읽어 반환
104
  return Image.open(image_path)
105
 
 
106
  @st.cache_data
107
+ def process_database_cached(data):
108
  database_embeddings = []
109
  database_info = []
110
  for item in data:
 
119
  temp_path = f"temp_{product_id}.jpg"
120
  image.save(temp_path, 'JPEG')
121
 
 
 
 
 
122
  database_info.append({
123
  'id': product_id,
124
  'category': item['카테고리'],
 
126
  'name': item['제품명'],
127
  'price': item['정가'],
128
  'discount': item['할인율'],
129
+ 'image_url': image_url,
130
+ 'temp_path': temp_path
131
  })
132
 
133
+ return database_info
134
+
135
+ def process_database(client, data):
136
+ database_info = process_database_cached(data)
137
+ database_embeddings = []
138
+
139
+ for item in database_info:
140
+ segmented_image = segment_image(item['temp_path'], client)
141
+ embedding = get_image_embedding(segmented_image)
142
+ database_embeddings.append(embedding)
143
+
144
  return np.vstack(database_embeddings), database_info
145
 
146
  # Streamlit app
 
153
  CLIENT = setup_roboflow_client(api_key)
154
 
155
  # Initialize database_embeddings and database_info
156
+ database_embeddings, database_info = process_database(CLIENT, data)
157
 
158
  uploaded_file = st.file_uploader("Choose an image...", type="jpg")
159
  if uploaded_file is not None: