Spaces:
Sleeping
Sleeping
Upload 11 files
Browse files
app.py
CHANGED
|
@@ -58,8 +58,12 @@ class ImageEvaluator:
|
|
| 58 |
|
| 59 |
total_files = len(image_files)
|
| 60 |
for i, img_path in enumerate(image_files):
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
# Extract metadata
|
| 65 |
metadata = self.metadata_extractor.extract_metadata(img_path)
|
|
@@ -89,8 +93,12 @@ class ImageEvaluator:
|
|
| 89 |
|
| 90 |
total_files = len(image_files)
|
| 91 |
for i, img_path in enumerate(image_files):
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# Get metadata if available
|
| 96 |
metadata = self.metadata_cache.get(img_path, {})
|
|
@@ -205,7 +213,7 @@ def create_interface():
|
|
| 205 |
'report_path': None
|
| 206 |
}
|
| 207 |
|
| 208 |
-
def upload_images(files
|
| 209 |
"""Handle image upload and processing."""
|
| 210 |
# Reset state
|
| 211 |
state['uploaded_images'] = []
|
|
@@ -221,8 +229,9 @@ def create_interface():
|
|
| 221 |
state['uploaded_images'] = image_paths
|
| 222 |
|
| 223 |
# Extract metadata and group images
|
| 224 |
-
progress
|
| 225 |
-
|
|
|
|
| 226 |
state['metadata_by_model'] = metadata_by_model
|
| 227 |
state['metadata_by_prompt'] = metadata_by_prompt
|
| 228 |
|
|
@@ -242,14 +251,15 @@ def create_interface():
|
|
| 242 |
f"Found {len(metadata_by_prompt)} unique prompts."
|
| 243 |
)
|
| 244 |
|
| 245 |
-
def evaluate_images(
|
| 246 |
"""Evaluate all uploaded images."""
|
| 247 |
if not state['uploaded_images']:
|
| 248 |
return "No images uploaded. Please upload images first."
|
| 249 |
|
| 250 |
# Evaluate images
|
| 251 |
-
progress
|
| 252 |
-
|
|
|
|
| 253 |
state['evaluation_results'] = evaluation_results
|
| 254 |
|
| 255 |
return f"Evaluated {len(evaluation_results)} images with all metrics."
|
|
@@ -406,4 +416,5 @@ def create_interface():
|
|
| 406 |
# Launch the application
|
| 407 |
if __name__ == "__main__":
|
| 408 |
interface = create_interface()
|
| 409 |
-
|
|
|
|
|
|
| 58 |
|
| 59 |
total_files = len(image_files)
|
| 60 |
for i, img_path in enumerate(image_files):
|
| 61 |
+
# Safe progress update without accessing internal attributes
|
| 62 |
+
if progress is not None:
|
| 63 |
+
try:
|
| 64 |
+
progress((i + 1) / total_files, f"Processing image {i+1}/{total_files}")
|
| 65 |
+
except Exception as e:
|
| 66 |
+
print(f"Progress update error (non-critical): {e}")
|
| 67 |
|
| 68 |
# Extract metadata
|
| 69 |
metadata = self.metadata_extractor.extract_metadata(img_path)
|
|
|
|
| 93 |
|
| 94 |
total_files = len(image_files)
|
| 95 |
for i, img_path in enumerate(image_files):
|
| 96 |
+
# Safe progress update without accessing internal attributes
|
| 97 |
+
if progress is not None:
|
| 98 |
+
try:
|
| 99 |
+
progress((i + 1) / total_files, f"Evaluating image {i+1}/{total_files}")
|
| 100 |
+
except Exception as e:
|
| 101 |
+
print(f"Progress update error (non-critical): {e}")
|
| 102 |
|
| 103 |
# Get metadata if available
|
| 104 |
metadata = self.metadata_cache.get(img_path, {})
|
|
|
|
| 213 |
'report_path': None
|
| 214 |
}
|
| 215 |
|
| 216 |
+
def upload_images(files):
|
| 217 |
"""Handle image upload and processing."""
|
| 218 |
# Reset state
|
| 219 |
state['uploaded_images'] = []
|
|
|
|
| 229 |
state['uploaded_images'] = image_paths
|
| 230 |
|
| 231 |
# Extract metadata and group images
|
| 232 |
+
# Use a simple progress message instead of Gradio Progress object
|
| 233 |
+
print("Extracting metadata...")
|
| 234 |
+
metadata_by_model, metadata_by_prompt = evaluator.process_images(image_paths)
|
| 235 |
state['metadata_by_model'] = metadata_by_model
|
| 236 |
state['metadata_by_prompt'] = metadata_by_prompt
|
| 237 |
|
|
|
|
| 251 |
f"Found {len(metadata_by_prompt)} unique prompts."
|
| 252 |
)
|
| 253 |
|
| 254 |
+
def evaluate_images():
|
| 255 |
"""Evaluate all uploaded images."""
|
| 256 |
if not state['uploaded_images']:
|
| 257 |
return "No images uploaded. Please upload images first."
|
| 258 |
|
| 259 |
# Evaluate images
|
| 260 |
+
# Use a simple progress message instead of Gradio Progress object
|
| 261 |
+
print("Evaluating images...")
|
| 262 |
+
evaluation_results = evaluator.evaluate_images(state['uploaded_images'])
|
| 263 |
state['evaluation_results'] = evaluation_results
|
| 264 |
|
| 265 |
return f"Evaluated {len(evaluation_results)} images with all metrics."
|
|
|
|
| 416 |
# Launch the application
|
| 417 |
if __name__ == "__main__":
|
| 418 |
interface = create_interface()
|
| 419 |
+
# Remove share=True for HuggingFace Spaces
|
| 420 |
+
interface.launch()
|