Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- README.md +3 -9
- app.py +138 -0
- best (5).pt +3 -0
- image.png +0 -0
- requirements.txt +17 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji: 🏢
|
| 4 |
-
colorFrom: gray
|
| 5 |
-
colorTo: green
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 4.19.2
|
| 8 |
app_file: app.py
|
| 9 |
-
|
|
|
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: plants_yolo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app_file: app.py
|
| 4 |
+
sdk: gradio
|
| 5 |
+
sdk_version: 3.44.4
|
| 6 |
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# from ultralytics import YOLO
|
| 2 |
+
# import cv2
|
| 3 |
+
# import matplotlib.pyplot as plt
|
| 4 |
+
# import matplotlib.patches as patches
|
| 5 |
+
# import numpy as np
|
| 6 |
+
# import requests
|
| 7 |
+
|
| 8 |
+
# model = YOLO('best (5).pt')
|
| 9 |
+
# img_url = 'https://www.greendna.in/cdn/shop/products/1296x728_Holy_Basil_1155x.jpg?v=1591462900'
|
| 10 |
+
# response = requests.get(img_url, stream=True)
|
| 11 |
+
# img_array = np.asarray(bytearray(response.content), dtype=np.uint8)
|
| 12 |
+
# img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
|
| 13 |
+
|
| 14 |
+
# classes_ = {0: 'anthurium', 1: 'clivia', 2: 'dieffenbachia', 3: 'dracaena', 4: 'gloxinia', 5: 'kalanchoe', 6: 'orchid', 7: 'sansevieria', 8: 'violet', 9: 'zamioculcas'}
|
| 15 |
+
|
| 16 |
+
# results = model.predict(source=img, conf = 0.4)
|
| 17 |
+
|
| 18 |
+
# # results = model.predict('api/default_1280-720-screenshot.webp', confidence=40, overlap=30).json()
|
| 19 |
+
# boxes = results[0].boxes.xyxy.tolist()
|
| 20 |
+
# classes = results[0].boxes.cls.tolist()
|
| 21 |
+
# names = results[0].names
|
| 22 |
+
# confidences = results[0].boxes.conf.tolist()
|
| 23 |
+
|
| 24 |
+
# print(boxes)
|
| 25 |
+
# print(classes)
|
| 26 |
+
# print(names)
|
| 27 |
+
# print(confidences)
|
| 28 |
+
|
| 29 |
+
# # Iterate through the results
|
| 30 |
+
# for box, cls, conf in zip(boxes, classes, confidences):
|
| 31 |
+
# x1, y1, x2, y2 = box
|
| 32 |
+
# confidence = conf
|
| 33 |
+
# detected_class = cls
|
| 34 |
+
# name = names[int(cls)]
|
| 35 |
+
|
| 36 |
+
# def plot_img_bbox(img, target):
|
| 37 |
+
# fig, a = plt.subplots(1,1)
|
| 38 |
+
# fig.set_size_inches(10, 10)
|
| 39 |
+
# a.imshow(img)
|
| 40 |
+
# for i, box in enumerate(target):
|
| 41 |
+
# #print(target['boxes'])
|
| 42 |
+
# x, y, width, height = box[0], box[1], box[2]-box[0], box[3]-box[1]
|
| 43 |
+
# # if arr[target['labels'][i]] == 'ad':
|
| 44 |
+
# rect = patches.Rectangle((x, y),
|
| 45 |
+
# width, height,
|
| 46 |
+
# linewidth = 2,
|
| 47 |
+
# edgecolor = 'r',
|
| 48 |
+
# facecolor = 'none')
|
| 49 |
+
# a.text(x, y-20, classes_[classes[i]], color='b', verticalalignment='top')
|
| 50 |
+
|
| 51 |
+
# a.add_patch(rect)
|
| 52 |
+
# plt.show()
|
| 53 |
+
|
| 54 |
+
# # if length of boxes is zero that means no deceptive popups were found
|
| 55 |
+
# plot_img_bbox(img, boxes)
|
| 56 |
+
|
| 57 |
+
import requests
|
| 58 |
+
from ultralytics import YOLO
|
| 59 |
+
import cv2
|
| 60 |
+
import matplotlib.pyplot as plt
|
| 61 |
+
import matplotlib.patches as patches
|
| 62 |
+
import numpy as np
|
| 63 |
+
import gradio as gr
|
| 64 |
+
|
| 65 |
+
model = YOLO('best (5).pt')
|
| 66 |
+
|
| 67 |
+
def plot_img_bbox(img, target, save_path, classes):
|
| 68 |
+
fig, a = plt.subplots(1, 1)
|
| 69 |
+
fig.set_size_inches(10, 10)
|
| 70 |
+
classes_ = {0: 'anthurium', 1: 'clivia', 2: 'dieffenbachia', 3: 'dracaena', 4: 'gloxinia', 5: 'kalanchoe', 6: 'orchid', 7: 'sansevieria', 8: 'violet', 9: 'zamioculcas'}
|
| 71 |
+
a.imshow(img)
|
| 72 |
+
for i, box in enumerate(target):
|
| 73 |
+
x, y, width, height = box[0], box[1], box[2] - box[0], box[3] - box[1]
|
| 74 |
+
rect = patches.Rectangle((x, y), width, height, linewidth=2, edgecolor='r', facecolor='none')
|
| 75 |
+
a.text(x, y - 20, classes_[classes[i]], color='b', verticalalignment='top')
|
| 76 |
+
a.add_patch(rect)
|
| 77 |
+
plt.savefig(save_path)
|
| 78 |
+
plt.close()
|
| 79 |
+
|
| 80 |
+
upload_url = upload_to_cloudinary(save_path)
|
| 81 |
+
|
| 82 |
+
return upload_url
|
| 83 |
+
|
| 84 |
+
def upload_to_cloudinary(local_file_path):
|
| 85 |
+
upload_url = 'https://api.cloudinary.com/v1_1/ddvajyjou/image/upload'
|
| 86 |
+
files = {'file': open(local_file_path, 'rb')}
|
| 87 |
+
params = {'upload_preset': 'nb6tvi1b'}
|
| 88 |
+
|
| 89 |
+
response = requests.post(upload_url, files=files, params=params)
|
| 90 |
+
|
| 91 |
+
if response.status_code == 200:
|
| 92 |
+
return response.json()['secure_url']
|
| 93 |
+
else:
|
| 94 |
+
print(f"Error uploading to Cloudinary: {response.status_code}")
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
def index(img_url):
|
| 98 |
+
response = requests.get(img_url, stream=True)
|
| 99 |
+
img_array = np.asarray(bytearray(response.content), dtype=np.uint8)
|
| 100 |
+
img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
|
| 101 |
+
|
| 102 |
+
print(img_url)
|
| 103 |
+
|
| 104 |
+
results = model.predict(source=img, conf = 0.4)
|
| 105 |
+
|
| 106 |
+
boxes = results[0].boxes.xyxy.tolist()
|
| 107 |
+
classes = results[0].boxes.cls.tolist()
|
| 108 |
+
names = results[0].names
|
| 109 |
+
confidences = results[0].boxes.conf.tolist()
|
| 110 |
+
|
| 111 |
+
print(boxes)
|
| 112 |
+
print(classes)
|
| 113 |
+
print(names)
|
| 114 |
+
print(confidences)
|
| 115 |
+
|
| 116 |
+
final_url = plot_img_bbox(img, boxes, 'image.png', classes)
|
| 117 |
+
return final_url
|
| 118 |
+
|
| 119 |
+
inputs_image_url = [
|
| 120 |
+
gr.Textbox(type="text", label="Image URL"),
|
| 121 |
+
]
|
| 122 |
+
|
| 123 |
+
outputs_result_dict = [
|
| 124 |
+
gr.Textbox(type="text", label="Result Dictionary"),
|
| 125 |
+
]
|
| 126 |
+
|
| 127 |
+
interface_image_url = gr.Interface(
|
| 128 |
+
fn=index,
|
| 129 |
+
inputs=inputs_image_url,
|
| 130 |
+
outputs=outputs_result_dict,
|
| 131 |
+
title="Popup detection",
|
| 132 |
+
cache_examples=False,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
gr.TabbedInterface(
|
| 136 |
+
[interface_image_url],
|
| 137 |
+
tab_names=['Image inference']
|
| 138 |
+
).queue().launch()
|
best (5).pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:249b37f0e31c33af4fd10aeb87a8e730ef1200b5966ac3ddf9e761d4e3e1f002
|
| 3 |
+
size 134273570
|
image.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask-mongoengine @ git+https://github.com/idoshr/flask-mongoengine.git@e244408acf440c4208f7ddcd6e5d819cb472e4da
|
| 2 |
+
flask
|
| 3 |
+
requests
|
| 4 |
+
datetime
|
| 5 |
+
pandas
|
| 6 |
+
numpy
|
| 7 |
+
gensim
|
| 8 |
+
requests
|
| 9 |
+
bs4
|
| 10 |
+
tensorflow
|
| 11 |
+
ultralytics
|
| 12 |
+
opencv-python
|
| 13 |
+
matplotlib
|
| 14 |
+
gunicorn
|
| 15 |
+
gevent
|
| 16 |
+
streamlit
|
| 17 |
+
gradio
|