cipherunhsiv commited on
Commit
10c2a17
·
verified ·
1 Parent(s): 4b53563

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ultralytics import YOLO
2
+ import cv2
3
+ import gradio as gr
4
+
5
+ def gap_det(img):
6
+ model = YOLO("best.pt")
7
+ input_image_path = img
8
+ results = model(input_image_path)
9
+
10
+ gap_up_count = 0
11
+ gap_down_count = 0
12
+
13
+ for result in results:
14
+ boxes = result.boxes.xyxy
15
+ classes = result.boxes.cls
16
+ confidences = result.boxes.conf
17
+ for cls in classes:
18
+ if cls == 0:
19
+ gap_down_count += 1
20
+ elif cls == 1:
21
+ gap_up_count += 1
22
+ annotated_image = result.plot()
23
+ output_image_path = "output_image.jpg"
24
+ cv2.imwrite(output_image_path, annotated_image)
25
+ annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
26
+ return annotated_image_rgb, gap_up_count, gap_down_count
27
+
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("# GAP UP and GAP DOWN Detection")
30
+ gr.Markdown("Upload an image to detect GAP UP and GAP DOWN patterns in stock market candlestick charts.")
31
+
32
+ with gr.Row():
33
+ input_image = gr.Image(label="Upload Image", type="filepath")
34
+ output_image = gr.Image(label="Detected Image")
35
+
36
+ with gr.Row():
37
+ gap_up_output = gr.Textbox(label="GAP UP Count")
38
+ gap_down_output = gr.Textbox(label="GAP DOWN Count")
39
+
40
+ submit_button = gr.Button("Detect")
41
+ submit_button.click(
42
+ fn=gap_det,
43
+ inputs=input_image,
44
+ outputs=[output_image, gap_up_output, gap_down_output]
45
+ )
46
+
47
+ demo.launch()