OzoneAsai commited on
Commit
cdfd52c
1 Parent(s): d83ba87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -203,9 +203,29 @@ def load_labels():
203
  with open(path) as f:
204
  labels = [line.strip() for line in f.readlines()]
205
  return labels
 
 
 
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  # Streamlit アプリケーションのメイン部分
208
  def main():
 
209
  st.sidebar.title("アップロードオプション")
210
  uploaded_photos = st.sidebar.file_uploader("写真をアップロードしてください", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
211
 
@@ -230,6 +250,7 @@ def main():
230
  photo_df.sort_values(by="Timestamp", inplace=True, ascending=False)
231
  photo_df.reset_index(drop=True, inplace=True)
232
  photo_df.to_csv(index_file_path, index=False)
 
233
 
234
  st.subheader("アップロードされた写真")
235
 
 
203
  with open(path) as f:
204
  labels = [line.strip() for line in f.readlines()]
205
  return labels
206
+ def update_photo_detail_in_csv(df, photo_folder):
207
+ photo_files = os.listdir(photo_folder)
208
+ new_df_rows = []
209
 
210
+ for file in photo_files:
211
+ file_path = os.path.join(photo_folder, file)
212
+ if not df['File Name'].eq(file).any():
213
+ image = Image.open(file_path)
214
+
215
+ # タグを予測して表示
216
+ result_threshold, result_all, result_text = predict_tags(image, 0.7)
217
+
218
+ new_df_rows.append([file, datetime.now(), ", ".join(result_all.keys())])
219
+
220
+ if new_df_rows:
221
+ new_df = pd.DataFrame(new_df_rows, columns=["File Name", "Timestamp", "Tags"])
222
+ df = pd.concat([df, new_df])
223
+ df.to_csv(index_file_path, index=False)
224
+
225
+ return df
226
  # Streamlit アプリケーションのメイン部分
227
  def main():
228
+
229
  st.sidebar.title("アップロードオプション")
230
  uploaded_photos = st.sidebar.file_uploader("写真をアップロードしてください", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
231
 
 
250
  photo_df.sort_values(by="Timestamp", inplace=True, ascending=False)
251
  photo_df.reset_index(drop=True, inplace=True)
252
  photo_df.to_csv(index_file_path, index=False)
253
+ photo_df = update_photo_detail_in_csv(photo_df, temp_folder)
254
 
255
  st.subheader("アップロードされた写真")
256