Update app.py
Browse files
app.py
CHANGED
|
@@ -75,37 +75,33 @@ def paginate_files(files, page, files_per_page):
|
|
| 75 |
return files[start_index:end_index]
|
| 76 |
|
| 77 |
# Function to display images with predictions and options
|
| 78 |
-
def display_images(images):
|
| 79 |
for i, file_path in enumerate(images):
|
| 80 |
file_ext = os.path.splitext(file_path)[1].lower()
|
| 81 |
|
| 82 |
# Check if index is within the range
|
| 83 |
-
if os.path.exists("temp/index.csv") and i < len(
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
if col2.button("削除", key=file_path):
|
| 106 |
-
os.remove(file_path)
|
| 107 |
-
# Update the displayed images after deletion
|
| 108 |
-
st.experimental_rerun()
|
| 109 |
|
| 110 |
# Main part of the app
|
| 111 |
if uploaded_files:
|
|
@@ -142,13 +138,12 @@ with open("temp/index.csv", mode='r', newline='', encoding='utf-8') as csv_file:
|
|
| 142 |
# Display images with predictions and options
|
| 143 |
current_page_files = paginate_files([row[0] for row in rows], st.session_state.page, files_per_page)
|
| 144 |
st.write("ファイル一覧:")
|
| 145 |
-
|
| 146 |
-
display_images(current_page_files)
|
| 147 |
|
| 148 |
# Blurのトグルを更新
|
| 149 |
st.session_state.blur_option = st.checkbox("NSFW画像にBlurをかける", value=st.session_state.blur_option)
|
| 150 |
|
| 151 |
-
# CSVに保存
|
| 152 |
if st.button("CSVに保存"):
|
| 153 |
csv_filename = "gradio_predictions_and_timestamps.csv"
|
| 154 |
with open(csv_filename, mode='w', newline='', encoding='utf-8') as csv_file:
|
|
|
|
| 75 |
return files[start_index:end_index]
|
| 76 |
|
| 77 |
# Function to display images with predictions and options
|
| 78 |
+
def display_images(images, rows):
|
| 79 |
for i, file_path in enumerate(images):
|
| 80 |
file_ext = os.path.splitext(file_path)[1].lower()
|
| 81 |
|
| 82 |
# Check if index is within the range
|
| 83 |
+
if os.path.exists("temp/index.csv") and i < len(rows):
|
| 84 |
+
gradio_nsfw_prediction = rows[i][1]
|
| 85 |
+
timestamp = rows[i][2]
|
| 86 |
+
|
| 87 |
+
st.write(f"**Prediction for {os.path.basename(file_path)} (NSFW):** {gradio_nsfw_prediction}")
|
| 88 |
+
st.write(f"**Timestamp:** {timestamp}")
|
| 89 |
+
|
| 90 |
+
if st.session_state.blur_option and gradio_nsfw_prediction.lower() == "nsfw":
|
| 91 |
+
blurred_img = apply_blur(file_path)
|
| 92 |
+
st.image(blurred_img, caption=os.path.basename(file_path), use_column_width=True)
|
| 93 |
+
else:
|
| 94 |
+
if file_ext in [".jpg", ".png"]:
|
| 95 |
+
st.image(Image.open(file_path), caption=os.path.basename(file_path), use_column_width=True)
|
| 96 |
+
col1, col2 = st.columns([4, 1])
|
| 97 |
+
with col1:
|
| 98 |
+
if file_ext in [".jpg", ".png"]:
|
| 99 |
+
st.image(Image.open(file_path), caption=os.path.basename(file_path), use_column_width=True)
|
| 100 |
+
with col2:
|
| 101 |
+
if col2.button("削除", key=file_path):
|
| 102 |
+
os.remove(file_path)
|
| 103 |
+
# Update the displayed images after deletion
|
| 104 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Main part of the app
|
| 107 |
if uploaded_files:
|
|
|
|
| 138 |
# Display images with predictions and options
|
| 139 |
current_page_files = paginate_files([row[0] for row in rows], st.session_state.page, files_per_page)
|
| 140 |
st.write("ファイル一覧:")
|
| 141 |
+
display_images(current_page_files, rows)
|
|
|
|
| 142 |
|
| 143 |
# Blurのトグルを更新
|
| 144 |
st.session_state.blur_option = st.checkbox("NSFW画像にBlurをかける", value=st.session_state.blur_option)
|
| 145 |
|
| 146 |
+
# CSVに保存ボタン
|
| 147 |
if st.button("CSVに保存"):
|
| 148 |
csv_filename = "gradio_predictions_and_timestamps.csv"
|
| 149 |
with open(csv_filename, mode='w', newline='', encoding='utf-8') as csv_file:
|