Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,22 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
from ultralytics import YOLO
|
4 |
-
import
|
5 |
import numpy as np
|
6 |
|
7 |
-
model
|
|
|
8 |
|
9 |
-
def detect_pattern(
|
10 |
-
results = model(
|
11 |
-
|
12 |
-
|
13 |
-
return image
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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 |
-
|
|
|
|
|
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()
|