jovian commited on
Commit
d77f8c0
·
1 Parent(s): c60a043
Files changed (1) hide show
  1. app.py +8 -96
app.py CHANGED
@@ -5,7 +5,6 @@ from sahi.predict import get_sliced_prediction
5
  from sahi import AutoDetectionModel
6
  from PIL import Image
7
  import plotly.graph_objects as go
8
- import spaces
9
  import torch
10
 
11
 
@@ -102,7 +101,7 @@ class Detection:
102
  if category_name in category_areas:
103
  category_areas[category_name].append(area)
104
 
105
- # Create individual area distribution histograms for each category
106
  individual_graphs = {}
107
  for category in ['Nicks', 'Dents', 'Scratches', 'Pittings']:
108
  areas = category_areas[category]
@@ -209,7 +208,6 @@ def upload_image(image):
209
  return image
210
 
211
 
212
- @spaces.GPU
213
  def apply_detection(image):
214
  """Run object detection on the uploaded image and return the annotated image."""
215
  # Convert image from PIL to NumPy array
@@ -252,75 +250,7 @@ body{
252
  background-color: #fff;
253
  }
254
 
255
- nav{
256
- padding: 0 80px;
257
- display: flex;
258
- align-items: center;
259
- justify-content: space-between;
260
- }
261
-
262
-
263
- .nav-logo{
264
- margin-top: 20px;
265
- }
266
 
267
- .astarlogo{
268
- width: 230px;
269
- display: flex;
270
- border-style: none;
271
- display: none;
272
- }
273
-
274
-
275
- .nav-links{
276
- list-style: none;
277
- display: flex;
278
- align-items: center;
279
- gap: 3rem ;
280
- }
281
-
282
- .link a{
283
- position: relative;
284
- padding-bottom: 0.75rem;
285
- color:#083484;
286
- font-size: 1rem;
287
- font-weight: 600;
288
- font-family: 'Poppins',sans-serif;
289
- }
290
-
291
- .link a::after {
292
- content: "";
293
- position: absolute;
294
- height: 2px;
295
- width: 0;
296
- bottom: 0;
297
- left: 0;
298
- background-color: #083484;
299
- transition: all 0.3s ease;
300
-
301
- }
302
-
303
- .link a:hover::after{
304
- width: 70%;
305
- }
306
-
307
- nav .login button{
308
- padding: 8px 14px;
309
- border: none;
310
- cursor: pointer;
311
- background-color: transparent;
312
- }
313
-
314
- nav .login button#signup{
315
- background-color: #083484;
316
- color: #fff;
317
- border-radius: 4px;
318
- margin-right: 14px;
319
- padding: 15px 20px;
320
- margin-top: 25px;
321
- display: none;
322
-
323
- }
324
 
325
  header{
326
  padding: 0 80px;
@@ -424,22 +354,6 @@ function refresh() {
424
  with gr.Blocks(css = css,js=js_func) as demo:
425
 
426
  gr.HTML("""
427
- <nav>
428
- <div class = "nav-logo" >
429
- <a href="#">
430
- <img class="astarlogo" src="" >
431
- </a>
432
- </div>
433
- <ul class="nav-links">
434
- <li class = "link"><a href="#">HOME</a></li>
435
- <li id = "link1" class = "link"><a href="#">OFFLINE DETECTION</a></li>
436
- <li id = "link2" class = "link"><a href="#">CONTACT US</a></li>
437
- </ul>
438
- <div class="login">
439
- <button id="signup">Get Started</button>
440
- </div>
441
- </nav>
442
-
443
 
444
  <header>
445
  <div class="left">
@@ -474,12 +388,10 @@ with gr.Blocks(css = css,js=js_func) as demo:
474
  with gr.Column():
475
  gr.Markdown("### Output")
476
  output_image_component = gr.Image(type="pil", label="Annotated Image")
 
 
 
477
 
478
- # Button for Object Detection below the columns
479
- with gr.Row(): # Create a new row for the button
480
- apply_detection_btn = gr.Button("Apply Detection")
481
- output_annotations = gr.State() # Store annotations
482
- apply_detection_btn.click(apply_detection, inputs=upload_image_component, outputs=[output_image_component, output_annotations])
483
 
484
  # Row for the graphs
485
  with gr.Row():
@@ -491,7 +403,7 @@ with gr.Blocks(css = css,js=js_func) as demo:
491
 
492
  # Button to generate graphs
493
  with gr.Row():
494
- graph_btn = gr.Button("Generate Graphs")
495
  graph_btn.click(generate_graphs_btn, inputs=output_annotations, outputs=[
496
  nicks_graph_component, dents_graph_component,
497
  scratches_graph_component, pittings_graph_component
@@ -501,14 +413,14 @@ with gr.Blocks(css = css,js=js_func) as demo:
501
  with gr.Row():
502
  frequency_graph_component = gr.Plot(label="Defect Frequency Distribution") # Frequency Graph
503
 
504
- # Additional row for frequency graph button (if needed)
505
  with gr.Row():
506
- freq_graph_btn = gr.Button("Refresh Frequency Graph")
507
  freq_graph_btn.click(detection.generate_frequency_graph,
508
  inputs=output_annotations,
509
  outputs=frequency_graph_component)
510
 
511
  # Launch the Gradio interface
512
- demo.launch(share=True)
513
 
514
 
 
5
  from sahi import AutoDetectionModel
6
  from PIL import Image
7
  import plotly.graph_objects as go
 
8
  import torch
9
 
10
 
 
101
  if category_name in category_areas:
102
  category_areas[category_name].append(area)
103
 
104
+ # Create individual area distribution histograms for each ctegory
105
  individual_graphs = {}
106
  for category in ['Nicks', 'Dents', 'Scratches', 'Pittings']:
107
  areas = category_areas[category]
 
208
  return image
209
 
210
 
 
211
  def apply_detection(image):
212
  """Run object detection on the uploaded image and return the annotated image."""
213
  # Convert image from PIL to NumPy array
 
250
  background-color: #fff;
251
  }
252
 
 
 
 
 
 
 
 
 
 
 
 
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
  header{
256
  padding: 0 80px;
 
354
  with gr.Blocks(css = css,js=js_func) as demo:
355
 
356
  gr.HTML("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
 
358
  <header>
359
  <div class="left">
 
388
  with gr.Column():
389
  gr.Markdown("### Output")
390
  output_image_component = gr.Image(type="pil", label="Annotated Image")
391
+ apply_detection_btn = gr.Button("Apply Detection")
392
+ output_annotations = gr.State() # Store annotations
393
+ apply_detection_btn.click(apply_detection, inputs=upload_image_component, outputs=[output_image_component, output_annotations])
394
 
 
 
 
 
 
395
 
396
  # Row for the graphs
397
  with gr.Row():
 
403
 
404
  # Button to generate graphs
405
  with gr.Row():
406
+ graph_btn = gr.Button("Generate Area Distribution Graphs")
407
  graph_btn.click(generate_graphs_btn, inputs=output_annotations, outputs=[
408
  nicks_graph_component, dents_graph_component,
409
  scratches_graph_component, pittings_graph_component
 
413
  with gr.Row():
414
  frequency_graph_component = gr.Plot(label="Defect Frequency Distribution") # Frequency Graph
415
 
416
+ # Row for frequency graph btn
417
  with gr.Row():
418
+ freq_graph_btn = gr.Button("Generate Frequency Graph")
419
  freq_graph_btn.click(detection.generate_frequency_graph,
420
  inputs=output_annotations,
421
  outputs=frequency_graph_component)
422
 
423
  # Launch the Gradio interface
424
+ demo.launch(auth=("user", "ois"),auth_message= "Enter username and password",share=True)
425
 
426