Spaces:
Runtime error
Runtime error
major(ui): modelscope and antd implementation
Browse files
app.py
CHANGED
|
@@ -248,67 +248,65 @@ def predict_image_with_html(img, confidence_threshold, augment_methods, rotate_d
|
|
| 248 |
return img_pil, forensics_images, html_content
|
| 249 |
|
| 250 |
with gr.Blocks(css="#post-gallery { overflow: hidden !important;} .grid-wrap{ overflow-y: hidden !important;}") as iface:
|
| 251 |
-
with
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
with antd.ConfigProvider():
|
| 311 |
-
# Example: Add a simple text input and output
|
| 312 |
text_input = gr.Textbox(label="Enter Text")
|
| 313 |
text_output = gr.Textbox(label="Processed Text")
|
| 314 |
text_button = gr.Button("Process Text")
|
|
|
|
| 248 |
return img_pil, forensics_images, html_content
|
| 249 |
|
| 250 |
with gr.Blocks(css="#post-gallery { overflow: hidden !important;} .grid-wrap{ overflow-y: hidden !important;}") as iface:
|
| 251 |
+
with ms.Application() as app:
|
| 252 |
+
with antd.ConfigProvider():
|
| 253 |
+
with gr.Accordion("Project OpenSight - Model Evaluations & Playground", open=False, elem_id="project_accordion"):
|
| 254 |
+
gr.Markdown("## OpenSight is a SOTA gen. image detection model, in pre-release prep.\n\nThis HF Space is a temporary home for us and the public to evaluate the shortcomings of current open source models.\n\n<-- Feel free to play around by starting with an image as we prepare our formal announcement.")
|
| 255 |
+
with gr.Tab("👀 Model Evals / Playground"):
|
| 256 |
+
gr.Markdown("# AI Generated Image / Deepfake Detection Models Evaluation")
|
| 257 |
+
|
| 258 |
+
with gr.Row():
|
| 259 |
+
with gr.Column(scale=1):
|
| 260 |
+
image_input = gr.Image(label="Upload Image to Analyze", sources=['upload'], type='pil')
|
| 261 |
+
with gr.Accordion("Settings (Optional)", open=False, elem_id="settings_accordion"):
|
| 262 |
+
augment_checkboxgroup = gr.CheckboxGroup(["rotate", "add_noise", "sharpen"], label="Augmentation Methods")
|
| 263 |
+
rotate_slider = gr.Slider(0, 45, value=2, step=1, label="Rotate Degrees", visible=False)
|
| 264 |
+
noise_slider = gr.Slider(0, 50, value=4, step=1, label="Noise Level", visible=False)
|
| 265 |
+
sharpen_slider = gr.Slider(0, 50, value=11, step=1, label="Sharpen Strength", visible=False)
|
| 266 |
+
confidence_slider = gr.Slider(0.0, 1.0, value=0.75, step=0.05, label="Confidence Threshold")
|
| 267 |
+
inputs = [image_input, confidence_slider, augment_checkboxgroup, rotate_slider, noise_slider, sharpen_slider]
|
| 268 |
+
predict_button = gr.Button("Predict")
|
| 269 |
+
augment_button = gr.Button("Augment & Predict")
|
| 270 |
+
image_output = gr.Image(label="Processed Image", visible=False)
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
with gr.Column(scale=2):
|
| 274 |
+
# Custom HTML component to display results in 5 columns
|
| 275 |
+
results_html = gr.HTML(label="Model Predictions")
|
| 276 |
+
forensics_gallery = gr.Gallery(label="Post Processed Images", visible=True, columns=[5], rows=[1], container=False, height="auto", object_fit="contain", elem_id="post-gallery")
|
| 277 |
+
|
| 278 |
+
outputs = [image_output, forensics_gallery, results_html]
|
| 279 |
+
|
| 280 |
+
# Show/hide rotate slider based on selected augmentation method
|
| 281 |
+
augment_checkboxgroup.change(lambda methods: gr.update(visible="rotate" in methods), inputs=[augment_checkboxgroup], outputs=[rotate_slider])
|
| 282 |
+
augment_checkboxgroup.change(lambda methods: gr.update(visible="add_noise" in methods), inputs=[augment_checkboxgroup], outputs=[noise_slider])
|
| 283 |
+
augment_checkboxgroup.change(lambda methods: gr.update(visible="sharpen" in methods), inputs=[augment_checkboxgroup], outputs=[sharpen_slider])
|
| 284 |
+
|
| 285 |
+
predict_button.click(
|
| 286 |
+
fn=predict_image_with_html,
|
| 287 |
+
inputs=inputs,
|
| 288 |
+
outputs=outputs
|
| 289 |
+
)
|
| 290 |
+
augment_button.click( # Connect Augment button to the function
|
| 291 |
+
fn=predict_image_with_html,
|
| 292 |
+
inputs=[
|
| 293 |
+
image_input,
|
| 294 |
+
confidence_slider,
|
| 295 |
+
gr.CheckboxGroup(["rotate", "add_noise", "sharpen"], value=["rotate", "add_noise", "sharpen"], visible=False), # Default values
|
| 296 |
+
rotate_slider,
|
| 297 |
+
noise_slider,
|
| 298 |
+
sharpen_slider
|
| 299 |
+
],
|
| 300 |
+
outputs=outputs
|
| 301 |
+
)
|
| 302 |
+
predict_button.click(
|
| 303 |
+
fn=None,
|
| 304 |
+
js="() => {document.getElementById('project_accordion').open = false;}", # Close the project accordion
|
| 305 |
+
inputs=[],
|
| 306 |
+
outputs=[]
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
with gr.Tab("🥇 Leaderboard"):
|
|
|
|
|
|
|
| 310 |
text_input = gr.Textbox(label="Enter Text")
|
| 311 |
text_output = gr.Textbox(label="Processed Text")
|
| 312 |
text_button = gr.Button("Process Text")
|