Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- README.md +6 -5
- app.py +130 -0
- gitattributes +35 -0
- gradio.css +8 -0
- requirements.txt +6 -0
README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Yolov8newultlt
|
| 3 |
+
emoji: 🌖
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.22.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
models: [MvitHYF/v8mvitcocoaseed2024]
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#app7.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from torchvision import transforms
|
| 6 |
+
from ultralyticsplus import YOLO, render_result
|
| 7 |
+
# import matplotlib.pyplot as plt
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
torch.hub.download_url_to_file(
|
| 11 |
+
'https://i.postimg.cc/g2xGJ4Qs/NSTA-Test-IMG-3276.jpg', 'NSTA.jpg')
|
| 12 |
+
torch.hub.download_url_to_file(
|
| 13 |
+
'https://i.postimg.cc/BZCSwj2T/NSTB-Test-IMG-1472.jpg', 'NSTB.jpg')
|
| 14 |
+
torch.hub.download_url_to_file(
|
| 15 |
+
'https://i.postimg.cc/yYY1q7Tw/NSTC-Test-IMG-0118.jpg', 'NSTC.jpg')
|
| 16 |
+
torch.hub.download_url_to_file(
|
| 17 |
+
'https://i.postimg.cc/zD9ZQX6z/KCCA-Test-IMG-3555.jpg', 'KCCA.jpg')
|
| 18 |
+
torch.hub.download_url_to_file(
|
| 19 |
+
'https://i.postimg.cc/vZLPXP7L/KCCB-Test-IMG-3733.jpg', 'KCCB.jpg')
|
| 20 |
+
torch.hub.download_url_to_file(
|
| 21 |
+
'https://i.postimg.cc/BZFYqFmF/KCCC-Test-IMG-3892.jpg', 'KCCC.jpg')
|
| 22 |
+
|
| 23 |
+
def detect_objects(image_path, selected_model):
|
| 24 |
+
# Open the image file and resize it
|
| 25 |
+
image = Image.open(image_path)
|
| 26 |
+
resized_image = image.resize((1024, 768))
|
| 27 |
+
|
| 28 |
+
#default
|
| 29 |
+
# model_path = ('MvitHYF/v8mvitcocoaseed2024')
|
| 30 |
+
|
| 31 |
+
# Load the model
|
| 32 |
+
nstcurrentmodel = "NST Model"
|
| 33 |
+
kcccurrentmodel = "KCC Model"
|
| 34 |
+
currentmodel = str(selected_model)
|
| 35 |
+
nstcurrentmodel = "NST Model"
|
| 36 |
+
if currentmodel == nstcurrentmodel:
|
| 37 |
+
print("this is nst model")
|
| 38 |
+
#best of NST Model
|
| 39 |
+
#model_path = ('code/runs/train45/best.pt')
|
| 40 |
+
model_path = ('MvitHYF/v8mvitcocoaseed2024')
|
| 41 |
+
elif currentmodel == kcccurrentmodel:
|
| 42 |
+
print("this is kcc model")
|
| 43 |
+
#model_path = ('code/runs/kcc/v8/train83/best.pt')
|
| 44 |
+
model_path = ('MvitHYF/kccv8mvitcocoaseed2024')
|
| 45 |
+
|
| 46 |
+
#model_path = ('code/runs/train45/best.pt')
|
| 47 |
+
# model_path = ('MvitHYF/v8mvitcocoaseed2024')
|
| 48 |
+
model = YOLO(model_path)
|
| 49 |
+
# model = YOLO('MvitHYF/v8mvitcocoaseed2024')
|
| 50 |
+
|
| 51 |
+
# Set model parameters
|
| 52 |
+
model.overrides['conf'] = 'null' # NMS confidence threshold
|
| 53 |
+
model.overrides['iou'] = 0.70 # NMS IoU threshold
|
| 54 |
+
model.overrides['agnostic_nms'] = True # NMS class-agnostic
|
| 55 |
+
model.overrides['max_det'] = 1000 # maximum number of detections per image
|
| 56 |
+
|
| 57 |
+
# Perform inference
|
| 58 |
+
results = model.predict(resized_image)
|
| 59 |
+
|
| 60 |
+
#debug check count
|
| 61 |
+
# print("see")
|
| 62 |
+
# print(results)
|
| 63 |
+
cls = results[0].boxes.cls
|
| 64 |
+
# print(cls)
|
| 65 |
+
strcls = str(cls)
|
| 66 |
+
# print(type(strcls))
|
| 67 |
+
# print(strcls)
|
| 68 |
+
count_classa = strcls.count('0')
|
| 69 |
+
# print('Count of classA:', count_classa)
|
| 70 |
+
count_classb = strcls.count('1')
|
| 71 |
+
# print('Count of classB', count_classb)
|
| 72 |
+
count_classc = strcls.count('2')
|
| 73 |
+
# print('Count of classC:', count_classc)
|
| 74 |
+
intcount_classa = int(count_classa)
|
| 75 |
+
intcount_classb = int(count_classb)
|
| 76 |
+
intcount_classc = int(count_classc)
|
| 77 |
+
total = intcount_classa + intcount_classb + intcount_classc
|
| 78 |
+
# print("end see")
|
| 79 |
+
|
| 80 |
+
# gr.Image(label="Pie Graph")
|
| 81 |
+
# Format the output to print the counts
|
| 82 |
+
output_counts = f"Totoal cocoa seeds: {total}\nClass A: {count_classa} seeds\nClass B: {count_classb} seeds\nClass C: {count_classc} seeds"
|
| 83 |
+
|
| 84 |
+
# Render results
|
| 85 |
+
render = render_result(model=model, image=resized_image, result=results[0])
|
| 86 |
+
|
| 87 |
+
print("Selected model:", selected_model)
|
| 88 |
+
|
| 89 |
+
#return render, output_counts, plotbar
|
| 90 |
+
return render, output_counts, "You have selected the " + str(selected_model)
|
| 91 |
+
|
| 92 |
+
#csspath = 'code/yolov8newultlt/gradio.css'
|
| 93 |
+
|
| 94 |
+
with gr.Blocks(theme='ParityError/LimeFace') as demo:
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Column():
|
| 98 |
+
gr.Interface(fn=detect_objects,
|
| 99 |
+
inputs=[gr.Image(type="filepath", label="Upload an Image"), gr.Dropdown(choices=["NST Model", "KCC Model"])],
|
| 100 |
+
outputs=[gr.Image(type="filepath", label="Result"), gr.Textbox(label="Detection Counts"), gr.Textbox(label="Selected Model")],
|
| 101 |
+
title="YOLOv8 Cocoa Seed Classification",
|
| 102 |
+
description="Upload an image to detect objects using YOLO.",
|
| 103 |
+
#html = gr.HTML(value="<p>This is another paragraph123.</p>"),
|
| 104 |
+
examples = [["NSTA.jpg"],
|
| 105 |
+
["NSTB.jpg"],
|
| 106 |
+
["NSTC.jpg"],
|
| 107 |
+
["KCCA.jpg"],
|
| 108 |
+
["KCCB.jpg"],
|
| 109 |
+
["KCCC.jpg"]],
|
| 110 |
+
cache_examples = bool(False)
|
| 111 |
+
#css=csspath,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# with gr.Row(): #original Column
|
| 115 |
+
# with gr.Row(): #original Column
|
| 116 |
+
# example = [[gr.Image(value="NSTA.jpg", interactive = bool(True)), gr.Markdown(value='**label 5**')],
|
| 117 |
+
# [gr.Image(value="NSTB.jpg", interactive = bool(True)), gr.Markdown(value='**label 5**')],
|
| 118 |
+
# [gr.Image(value="NSTC.jpg", interactive = bool(True)), gr.Markdown(value='**label 5**')],
|
| 119 |
+
# [gr.Image(value="KCCA.jpg", interactive = bool(True)), gr.Markdown(value='**label 5**')],
|
| 120 |
+
# [gr.Image(value="KCCB.jpg", interactive = bool(True)), gr.Markdown(value='**label 5**')],
|
| 121 |
+
# [gr.Image(value="KCCC.jpg", interactive = bool(True)), gr.Markdown(value='**label 5**')]]
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
with gr.Row():
|
| 125 |
+
with gr.Row():
|
| 126 |
+
# gr.HTML(value="<b>Class A</b> <p>Class A is the best from all 3 classes. It have the best of physical appreance eg. shape, size, texture</p>"),
|
| 127 |
+
gr.HTML(value="<p> NSTA NSTB NTSC KCCA KCCB KCCC</p> <dl> <dt><b>Class A</b></dt> <dd>Class A is the best from all 3 classes. It have the best of physical appreance eg. shape, size, texture</dd> </dl> <dt><b>Class B</b></dt> <dd>Class B most of the cocoa seed have physical appreance similar to class A. <br> But the size must me smaller and texture is not smmoth as class A</dd> <dt><b>Class C</b></dt> <dd>Class C is the worst from all 3 classes. Its the smallest, rough texter and have a irregular shape </dd> </dl></dl>")
|
| 128 |
+
|
| 129 |
+
if __name__ == "__main__":
|
| 130 |
+
demo.queue().launch(share=True)
|
gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
gradio.css
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* gradio.css */
|
| 2 |
+
|
| 3 |
+
/* Target the images within the gradio app */
|
| 4 |
+
img {
|
| 5 |
+
width: 1024px; /* Set width directly */
|
| 6 |
+
height: 768px; /* Set height directly */
|
| 7 |
+
margin: 10px; /* Optional: add some space around the images */
|
| 8 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
numpy
|
| 3 |
+
Pillow
|
| 4 |
+
torch
|
| 5 |
+
torchvision
|
| 6 |
+
ultralyticsplus
|