Devon12 commited on
Commit
0fa7c44
1 Parent(s): 0f4d92a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -12,13 +12,13 @@ def yolov8_func(image,
12
  # Load the YOLOv8 model
13
  model_path = "best.pt"
14
  model = YOLO(model_path)
15
-
16
  # Make predictions
17
  result = model.predict(image, conf=conf_thresold, iou=iou_thresold, imgsz=image_size)
18
 
19
  # Access object detection results
20
  boxes = result[0].boxes
21
- num_boxes = len(boxes) # Count the number of bounding boxes (detections)
22
 
23
  # Print object detection details (optional)
24
  print("Object type: ", boxes.cls)
@@ -43,26 +43,27 @@ def yolov8_func(image,
43
  # Render the result (with bounding boxes/labels)
44
  render = render_result(model=model, image=image, result=result[0])
45
 
46
- # Save the rendered image (with predictions)
47
  predicted_image_save_path = "predicted_image.jpg"
48
  render.save(predicted_image_save_path)
49
-
50
- # Return the saved image, severity, and recommendation for Gradio output
51
  return predicted_image_save_path, f"Acne condition: {severity}", recommendation
52
 
53
  # Define inputs for the Gradio app
54
  inputs = [
55
  gr.Image(type="filepath", label="Input Image"),
56
  gr.Slider(minimum=320, maximum=1280, step=32, value=640, label="Image Size"),
57
- gr.Slider(minimum=0, maximum=1, step=0.05, value=0.25, label="Confidence Threshold"),
58
- gr.Slider(minimum=0, maximum=1, step=0.05, value=0.45, label="IOU Threshold")
59
  ]
60
 
61
- # Define the output for the Gradio app (image + text for severity and recommendation)
 
 
 
 
 
62
  outputs = [
63
- gr.Image(type="filepath", label="Output Image"),
64
- gr.Textbox(label="Acne Condition"),
65
- gr.Textbox(label="Recommendation")
66
  ]
67
 
68
  # Set the title of the Gradio app
@@ -75,4 +76,4 @@ yolo_app = gr.Interface(fn=yolov8_func,
75
  title=title)
76
 
77
  # Launch the app
78
- yolo_app.launch(debug=True)
 
12
  # Load the YOLOv8 model
13
  model_path = "best.pt"
14
  model = YOLO(model_path)
15
+
16
  # Make predictions
17
  result = model.predict(image, conf=conf_thresold, iou=iou_thresold, imgsz=image_size)
18
 
19
  # Access object detection results
20
  boxes = result[0].boxes
21
+ num_boxes = len(boxes)
22
 
23
  # Print object detection details (optional)
24
  print("Object type: ", boxes.cls)
 
43
  # Render the result (with bounding boxes/labels)
44
  render = render_result(model=model, image=image, result=result[0])
45
 
 
46
  predicted_image_save_path = "predicted_image.jpg"
47
  render.save(predicted_image_save_path)
 
 
48
  return predicted_image_save_path, f"Acne condition: {severity}", recommendation
49
 
50
  # Define inputs for the Gradio app
51
  inputs = [
52
  gr.Image(type="filepath", label="Input Image"),
53
  gr.Slider(minimum=320, maximum=1280, step=32, value=640, label="Image Size"),
54
+ gr.Slider(minimum=0, maximum=1, step=0.05, value=0.15, label="Confidence Threshold"),
55
+ gr.Slider(minimum=0, maximum=1, step=0.05, value=0.2, label="IOU Threshold")
56
  ]
57
 
58
+ # Use a Row layout to align the textboxes for condition and recommendation
59
+ output_image = gr.Image(type="filepath", label="Output Image")
60
+ acne_condition = gr.Textbox(label="Acne Condition")
61
+ recommendation = gr.Textbox(label="Recommendation")
62
+
63
+ # Define the layout using Rows and Columns
64
  outputs = [
65
+ output_image,
66
+ gr.Row([acne_condition, recommendation])
 
67
  ]
68
 
69
  # Set the title of the Gradio app
 
76
  title=title)
77
 
78
  # Launch the app
79
+ yolo_app.launch(debug=True)