Spaces:
Runtime error
Runtime error
Commit
Β·
ed9854e
0
Parent(s):
Duplicate from foduucom/CandleStickScan-Stock-trading-yolov8
Browse filesCo-authored-by: Nehul Agrawal <[email protected]>
- .gitattributes +36 -0
- README.md +13 -0
- app.py +132 -0
- requirements.txt +5 -0
- test/test1.jpg +0 -0
- test/test2.jpg +0 -0
- test/testvideo.mp4 +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
+
test/testvideo.mp4 filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: CandleStickScan Stock Trading Yolov8
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.40.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
duplicated_from: foduucom/CandleStickScan-Stock-trading-yolov8
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
from ultralyticsplus import YOLO, render_result
|
| 7 |
+
|
| 8 |
+
# Model Heading and Description
|
| 9 |
+
model_heading = "CandleStickScan: Pattern Recognition for Trading Success"
|
| 10 |
+
description = """ π―οΈ Light up your trading game with CandleStickScan! We decode candlestick mysteries like trading Sherlock! π΅οΈββοΈ From 'Head and Shoulders' to 'W-Bottom', we've got patterns covered. Powered by Foduu AI's magic, we'll be your trading Gandalf. Whether you're a trading guru or just starting, we've got your back. πΌπ°
|
| 11 |
+
π Trading with CandleScan is like having a secret trading sauce. Curious? Reach out at [email protected] and unveil the magic! Liking us won't give you superpowers, but it's a step towards trading wizardry! πππ―οΈ
|
| 12 |
+
π§ Contact us: [email protected]
|
| 13 |
+
π Like | Join the Trading Adventure!"""
|
| 14 |
+
|
| 15 |
+
image_path= [['test/test1.jpg', 'foduucom/stockmarket-pattern-detection-yolov8', 640, 0.25, 0.45], ['test/test2.jpg', 'foduucom/stockmarket-pattern-detection-yolov8', 640, 0.25, 0.45]]
|
| 16 |
+
|
| 17 |
+
# Load YOLO model
|
| 18 |
+
model = YOLO('foduucom/stockmarket-pattern-detection-yolov8')
|
| 19 |
+
|
| 20 |
+
#############################################################Image Inference############################################################
|
| 21 |
+
def yolov8_img_inference(
|
| 22 |
+
image: gr.inputs.Image = None,
|
| 23 |
+
model_path: gr.inputs.Dropdown = None,
|
| 24 |
+
image_size: gr.inputs.Slider = 640,
|
| 25 |
+
conf_threshold: gr.inputs.Slider = 0.25,
|
| 26 |
+
iou_threshold: gr.inputs.Slider = 0.45,
|
| 27 |
+
):
|
| 28 |
+
"""
|
| 29 |
+
YOLOv8 inference function
|
| 30 |
+
Args:
|
| 31 |
+
image: Input image
|
| 32 |
+
model_path: Path to the model
|
| 33 |
+
image_size: Image size
|
| 34 |
+
conf_threshold: Confidence threshold
|
| 35 |
+
iou_threshold: IOU threshold
|
| 36 |
+
Returns:
|
| 37 |
+
Rendered image
|
| 38 |
+
"""
|
| 39 |
+
model = YOLO(model_path)
|
| 40 |
+
model.overrides['conf'] = conf_threshold
|
| 41 |
+
model.overrides['iou']= iou_threshold
|
| 42 |
+
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
| 43 |
+
model.overrides['max_det'] = 1000
|
| 44 |
+
# image = read_image(image)
|
| 45 |
+
results = model.predict(image)
|
| 46 |
+
render = render_result(model=model, image=image, result=results[0])
|
| 47 |
+
|
| 48 |
+
return render
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
inputs_image = [
|
| 52 |
+
gr.inputs.Image(type="filepath", label="Input Image"),
|
| 53 |
+
gr.inputs.Dropdown(["foduucom/stockmarket-pattern-detection-yolov8"],
|
| 54 |
+
default="foduucom/stockmarket-pattern-detection-yolov8", label="Model"),
|
| 55 |
+
gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
|
| 56 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
|
| 57 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
outputs_image =gr.outputs.Image(type="filepath", label="Output Image")
|
| 61 |
+
interface_image = gr.Interface(
|
| 62 |
+
fn=yolov8_img_inference,
|
| 63 |
+
inputs=inputs_image,
|
| 64 |
+
outputs=outputs_image,
|
| 65 |
+
title=model_heading,
|
| 66 |
+
description=description,
|
| 67 |
+
examples=image_path,
|
| 68 |
+
cache_examples=False,
|
| 69 |
+
theme='huggingface'
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
##################################################Video Inference################################################################
|
| 73 |
+
def show_preds_video(
|
| 74 |
+
video_path: str = None,
|
| 75 |
+
model_path: str = None,
|
| 76 |
+
image_size: int = 640,
|
| 77 |
+
conf_threshold: float = 0.25,
|
| 78 |
+
iou_threshold: float = 0.45,
|
| 79 |
+
):
|
| 80 |
+
cap = cv2.VideoCapture(video_path)
|
| 81 |
+
|
| 82 |
+
while cap.isOpened():
|
| 83 |
+
success, frame = cap.read()
|
| 84 |
+
|
| 85 |
+
if success:
|
| 86 |
+
model = YOLO(model_path)
|
| 87 |
+
model.overrides['conf'] = conf_threshold
|
| 88 |
+
model.overrides['iou'] = iou_threshold
|
| 89 |
+
model.overrides['agnostic_nms'] = False
|
| 90 |
+
model.overrides['max_det'] = 1000
|
| 91 |
+
results = model.predict(frame)
|
| 92 |
+
annotated_frame = results[0].plot()
|
| 93 |
+
|
| 94 |
+
# Do not display the frame using cv2.imshow
|
| 95 |
+
# cv2.imshow("YOLOv8 Inference", annotated_frame)
|
| 96 |
+
|
| 97 |
+
# Break the loop if 'q' is pressed
|
| 98 |
+
if cv2.waitKey(1) & 0xFF == ord("q"):
|
| 99 |
+
break
|
| 100 |
+
else:
|
| 101 |
+
break
|
| 102 |
+
|
| 103 |
+
cap.release()
|
| 104 |
+
cv2.destroyAllWindows()
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
inputs_video = [
|
| 108 |
+
gr.components.Video(type="filepath", label="Input Video"),
|
| 109 |
+
gr.inputs.Dropdown(["foduucom/stockmarket-pattern-detection-yolov8"],
|
| 110 |
+
default="foduucom/stockmarket-pattern-detection-yolov8", label="Model"),
|
| 111 |
+
gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
|
| 112 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
|
| 113 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
|
| 114 |
+
|
| 115 |
+
]
|
| 116 |
+
outputs_video = gr.outputs.Image(type="filepath", label="Output Video")
|
| 117 |
+
video_path=[['test/testvideo.mp4','foduucom/stockmarket-pattern-detection-yolov8', 640, 0.25, 0.45]]
|
| 118 |
+
interface_video = gr.Interface(
|
| 119 |
+
fn=show_preds_video,
|
| 120 |
+
inputs=inputs_video,
|
| 121 |
+
outputs=outputs_video,
|
| 122 |
+
title=model_heading,
|
| 123 |
+
description=description,
|
| 124 |
+
examples=video_path,
|
| 125 |
+
cache_examples=False,
|
| 126 |
+
theme='huggingface'
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
gr.TabbedInterface(
|
| 130 |
+
[interface_image, interface_video],
|
| 131 |
+
tab_names=['Image inference', 'Video inference']
|
| 132 |
+
).queue().launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
ultralytics==8.0.43
|
| 3 |
+
ultralyticsplus==0.0.28
|
| 4 |
+
opencv_python
|
| 5 |
+
requests>=2.23.0
|
test/test1.jpg
ADDED
|
test/test2.jpg
ADDED
|
test/testvideo.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:355fd1ca1526a4ff71df8a93dd69a7bc582e60ad33f2d12aa35fb54482814818
|
| 3 |
+
size 2124258
|