Spaces:
Sleeping
Sleeping
Delete gradio_app
Browse files- gradio_app/.gitkeep +0 -0
- gradio_app/__init__.py +0 -0
- gradio_app/inference.py +0 -57
gradio_app/.gitkeep
DELETED
File without changes
|
gradio_app/__init__.py
DELETED
File without changes
|
gradio_app/inference.py
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import sys
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
-
# Append the path to the inference script's directory
|
6 |
-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'slimface', 'inference')))
|
7 |
-
from end2end_inference import cinference_and_confirm
|
8 |
-
|
9 |
-
def run_inference(image, reference_dict_path, index_to_class_mapping_path, model_path,
|
10 |
-
edgeface_model_name="edgeface_base", edgeface_model_dir="ckpts/idiap",
|
11 |
-
algorithm="yolo", accelerator="auto", resolution=224, similarity_threshold=0.6):
|
12 |
-
# Save uploaded image temporarily in apps/gradio_app/
|
13 |
-
temp_image_path = os.path.join(os.path.dirname(__file__), "temp_image.jpg")
|
14 |
-
image.save(temp_image_path)
|
15 |
-
|
16 |
-
# Create args object to mimic command-line arguments
|
17 |
-
class Args:
|
18 |
-
def __init__(self):
|
19 |
-
self.unknown_image_path = temp_image_path
|
20 |
-
self.reference_dict_path = reference_dict_path.name if reference_dict_path else None
|
21 |
-
self.index_to_class_mapping_path = index_to_class_mapping_path.name if index_to_class_mapping_path else None
|
22 |
-
self.model_path = model_path.name if model_path else None
|
23 |
-
self.edgeface_model_name = edgeface_model_name
|
24 |
-
self.edgeface_model_dir = edgeface_model_dir
|
25 |
-
self.algorithm = algorithm
|
26 |
-
self.accelerator = accelerator
|
27 |
-
self.resolution = resolution
|
28 |
-
self.similarity_threshold = similarity_threshold
|
29 |
-
|
30 |
-
args = Args()
|
31 |
-
|
32 |
-
# Validate inputs
|
33 |
-
if not all([args.reference_dict_path, args.index_to_class_mapping_path, args.model_path]):
|
34 |
-
return "Error: Please provide all required files (reference dict, index-to-class mapping, and model)."
|
35 |
-
|
36 |
-
try:
|
37 |
-
# Call the inference function from end2end_inference.py
|
38 |
-
results = cinference_and_confirm(args)
|
39 |
-
|
40 |
-
# Format output
|
41 |
-
output = ""
|
42 |
-
for result in results:
|
43 |
-
output += f"Image: {result['image_path']}\n"
|
44 |
-
output += f"Predicted Class: {result['predicted_class']}\n"
|
45 |
-
output += f"Confidence: {result['confidence']:.4f}\n"
|
46 |
-
output += f"Similarity: {result.get('similarity', 'N/A'):.4f}\n"
|
47 |
-
output += f"Confirmed: {result.get('confirmed', 'N/A')}\n\n"
|
48 |
-
|
49 |
-
return output
|
50 |
-
|
51 |
-
except Exception as e:
|
52 |
-
return f"Error: {str(e)}"
|
53 |
-
|
54 |
-
finally:
|
55 |
-
# Clean up temporary image
|
56 |
-
if os.path.exists(temp_image_path):
|
57 |
-
os.remove(temp_image_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|