Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ def run_inference(image, model_type, illusion_type, eps_value, num_iterations):
|
|
| 26 |
config = get_inference_configs(eps=eps, n_itr=int(num_iterations))
|
| 27 |
|
| 28 |
# Run generative inference
|
| 29 |
-
|
| 30 |
|
| 31 |
# Create animation frames
|
| 32 |
frames = []
|
|
@@ -35,8 +35,11 @@ def run_inference(image, model_type, illusion_type, eps_value, num_iterations):
|
|
| 35 |
step_pil = Image.fromarray((step_image.permute(1, 2, 0).cpu().numpy() * 255).astype(np.uint8))
|
| 36 |
frames.append(step_pil)
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Define the interface
|
| 42 |
with gr.Blocks(title="Generative Inference Demo") as demo:
|
|
@@ -77,7 +80,7 @@ with gr.Blocks(title="Generative Inference Demo") as demo:
|
|
| 77 |
[os.path.join("stimuli", "Kanizsa_square.jpg"), "robust_resnet50", "Kanizsa", 0.5, 50],
|
| 78 |
[os.path.join("stimuli", "face_vase.png"), "robust_resnet50", "Face-Vase", 0.5, 50],
|
| 79 |
[os.path.join("stimuli", "figure_ground.png"), "robust_resnet50", "Figure-Ground", 0.7, 100],
|
| 80 |
-
[os.path.join("stimuli", "
|
| 81 |
]
|
| 82 |
|
| 83 |
gr.Examples(examples=examples, inputs=[image_input, model_choice, illusion_type, eps_slider, iterations_slider])
|
|
|
|
| 26 |
config = get_inference_configs(eps=eps, n_itr=int(num_iterations))
|
| 27 |
|
| 28 |
# Run generative inference
|
| 29 |
+
output_image, all_steps = model.inference(image, model_type, config)
|
| 30 |
|
| 31 |
# Create animation frames
|
| 32 |
frames = []
|
|
|
|
| 35 |
step_pil = Image.fromarray((step_image.permute(1, 2, 0).cpu().numpy() * 255).astype(np.uint8))
|
| 36 |
frames.append(step_pil)
|
| 37 |
|
| 38 |
+
# Convert the final output image to PIL
|
| 39 |
+
final_image = Image.fromarray((output_image.permute(1, 2, 0).cpu().numpy() * 255).astype(np.uint8))
|
| 40 |
+
|
| 41 |
+
# Return the final inferred image and the animation frames directly
|
| 42 |
+
return final_image, frames
|
| 43 |
|
| 44 |
# Define the interface
|
| 45 |
with gr.Blocks(title="Generative Inference Demo") as demo:
|
|
|
|
| 80 |
[os.path.join("stimuli", "Kanizsa_square.jpg"), "robust_resnet50", "Kanizsa", 0.5, 50],
|
| 81 |
[os.path.join("stimuli", "face_vase.png"), "robust_resnet50", "Face-Vase", 0.5, 50],
|
| 82 |
[os.path.join("stimuli", "figure_ground.png"), "robust_resnet50", "Figure-Ground", 0.7, 100],
|
| 83 |
+
[os.path.join("stimuli", "Neon_Color_Circle.jpg"), "robust_resnet50", "Neon-Color", 0.3, 80]
|
| 84 |
]
|
| 85 |
|
| 86 |
gr.Examples(examples=examples, inputs=[image_input, model_choice, illusion_type, eps_slider, iterations_slider])
|