Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,29 +7,35 @@ import torch
|
|
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 |
-
#
|
|
|
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":
|
|
|
23 |
})
|
24 |
return detections
|
25 |
|
26 |
-
# Erstelle Gradio-Schnittstelle
|
27 |
iface = gr.Interface(
|
28 |
fn=analyze_image,
|
29 |
-
inputs=
|
|
|
|
|
|
|
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
|
|
|
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, prompt):
|
11 |
+
# Verwende den Prompt (falls nötig, hier als Kontext für die Verarbeitung)
|
12 |
+
# YOLOv8 ignoriert den Prompt direkt, daher speichern wir ihn für die Logik
|
13 |
results = model.predict(source=image, save=False)
|
|
|
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 |
+
# Farben basierend auf Label oder Prompt (z. B. "bullish" für grün)
|
20 |
+
color = "green" if "bullish" in prompt.lower() or "Bullish" in label else "red"
|
21 |
detections.append({
|
22 |
"pattern": label,
|
23 |
"confidence": confidence,
|
24 |
+
"color": color,
|
25 |
+
"prompt_used": prompt # Rückgabe des Prompts zur Überprüfung
|
26 |
})
|
27 |
return detections
|
28 |
|
29 |
+
# Erstelle Gradio-Schnittstelle mit Bild- und Text-Eingabe
|
30 |
iface = gr.Interface(
|
31 |
fn=analyze_image,
|
32 |
+
inputs=[
|
33 |
+
gr.Image(type="pil", label="Upload TradingView Screenshot"),
|
34 |
+
gr.Textbox(label="Prompt", placeholder="Enter your prompt, e.g., 'Detect candlestick patterns and colors'")
|
35 |
+
],
|
36 |
outputs="json",
|
37 |
title="Candlestick Pattern Detection",
|
38 |
+
description="Upload a TradingView screenshot and provide a prompt to detect candlestick patterns and colors."
|
39 |
)
|
40 |
|
41 |
# Starte die App
|