Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Lade das Modell
|
| 7 |
+
model_path = hf_hub_download(repo_id="foduucom/stockmarket-pattern-detection-yolov8", filename="model.pt")
|
| 8 |
+
model = YOLO(model_path)
|
| 9 |
+
|
| 10 |
+
def analyze_image(image):
|
| 11 |
+
# Führe Objekterkennung durch
|
| 12 |
+
results = model.predict(source=image, save=False)
|
| 13 |
+
# Extrahiere Ergebnisse
|
| 14 |
+
detections = []
|
| 15 |
+
for result in results:
|
| 16 |
+
for box in result.boxes:
|
| 17 |
+
label = result.names[int(box.cls)]
|
| 18 |
+
confidence = float(box.conf)
|
| 19 |
+
detections.append({
|
| 20 |
+
"pattern": label,
|
| 21 |
+
"confidence": confidence,
|
| 22 |
+
"color": "green" if "Bullish" in label else "red"
|
| 23 |
+
})
|
| 24 |
+
return detections
|
| 25 |
+
|
| 26 |
+
# Erstelle Gradio-Schnittstelle
|
| 27 |
+
iface = gr.Interface(
|
| 28 |
+
fn=analyze_image,
|
| 29 |
+
inputs=gr.Image(type="pil"),
|
| 30 |
+
outputs="json",
|
| 31 |
+
title="Candlestick Pattern Detection",
|
| 32 |
+
description="Upload a TradingView screenshot to detect candlestick patterns and colors."
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Starte die App
|
| 36 |
+
iface.launch()
|