nick5363 commited on
Commit
0cbf3f9
·
verified ·
1 Parent(s): 4c4fc7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -1,28 +1,22 @@
1
-
2
  import gradio as gr
3
  from ultralytics import YOLO
4
- import cv2
5
  import numpy as np
6
 
7
- model = YOLO("foduucom/stockmarket-pattern-detection-yolov8")
 
8
 
9
- def detect_pattern(image):
10
- results = model(image)
11
- if results and results[0].plot:
12
- return cv2.cvtColor(results[0].plot(), cv2.COLOR_RGB2BGR)
13
- return image
14
 
15
- with gr.Blocks(theme=gr.themes.Base()) as app:
16
- gr.Markdown("# Stock Market Pattern Detection (YOLOv8)")
17
- with gr.Tabs():
18
- with gr.Tab("Upload Image"):
19
- image_input = gr.Image(type="numpy")
20
- image_output = gr.Image()
21
- detect_btn = gr.Button("Detect Pattern")
22
- detect_btn.click(fn=detect_pattern, inputs=image_input, outputs=image_output)
23
- with gr.Tab("Real-time (Camera)"):
24
- webcam_input = gr.Image(source="webcam", streaming=True)
25
- webcam_output = gr.Image()
26
- webcam_input.change(fn=detect_pattern, inputs=webcam_input, outputs=webcam_output)
27
 
28
- app.launch()
 
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
+ from PIL import Image
4
  import numpy as np
5
 
6
+ # Load model từ file
7
+ model = YOLO("model.pt")
8
 
9
+ def detect_pattern(img):
10
+ results = model(img)
11
+ annotated_img = results[0].plot() # Vẽ kết quả lên ảnh
12
+ return Image.fromarray(annotated_img)
 
13
 
14
+ demo = gr.Interface(
15
+ fn=detect_pattern,
16
+ inputs=gr.Image(type="pil", label="Upload Chart"),
17
+ outputs=gr.Image(type="pil", label="Detected Pattern"),
18
+ title="Stock Pattern Detection (YOLOv8)",
19
+ description="Upload a stock chart image to detect patterns."
20
+ )
 
 
 
 
 
21
 
22
+ demo.launch()