Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,20 @@ import numpy as np
|
|
| 4 |
from ultralytics import YOLO
|
| 5 |
import easyocr
|
| 6 |
import logging
|
|
|
|
| 7 |
|
| 8 |
# Logging einrichten
|
| 9 |
logging.basicConfig(level=logging.INFO)
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Lade YOLOv8-Modell
|
| 13 |
try:
|
| 14 |
logger.info("Loading YOLOv8 model")
|
|
@@ -102,18 +111,4 @@ def analyze_image(image, prompt):
|
|
| 102 |
return {"prompt": prompt, "description": "Error analyzing candles. Try a clearer screenshot with visible candles and prices."}
|
| 103 |
|
| 104 |
else:
|
| 105 |
-
return {"prompt": prompt, "description": "Unsupported prompt. Use 'Was siehst du auf dem Bild?' or 'List last 8 candles with their colors'."
|
| 106 |
-
|
| 107 |
-
# Erstelle Gradio-Schnittstelle
|
| 108 |
-
iface = gr.Interface(
|
| 109 |
-
fn=analyze_image,
|
| 110 |
-
inputs=[
|
| 111 |
-
gr.Image(type="pil", label="Upload an Image"),
|
| 112 |
-
gr.Textbox(label="Prompt", placeholder="Enter your prompt, e.g., 'Was siehst du auf dem Bild?' or 'List last 8 candles with their colors'")
|
| 113 |
-
],
|
| 114 |
-
outputs="json",
|
| 115 |
-
title="Chart Analysis with YOLOv8 and EasyOCR",
|
| 116 |
-
description="Upload a TradingView screenshot to analyze candlesticks or get a general description."
|
| 117 |
-
)
|
| 118 |
-
|
| 119 |
-
iface.launch()
|
|
|
|
| 4 |
from ultralytics import YOLO
|
| 5 |
import easyocr
|
| 6 |
import logging
|
| 7 |
+
import torch.serialization # Für Allowlist
|
| 8 |
|
| 9 |
# Logging einrichten
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
+
# Allowlist für YOLOv8-Modell
|
| 14 |
+
try:
|
| 15 |
+
logger.info("Adding ultralytics.nn.tasks.DetectionModel to PyTorch safe globals")
|
| 16 |
+
torch.serialization.add_safe_globals(['ultralytics.nn.tasks.DetectionModel'])
|
| 17 |
+
except Exception as e:
|
| 18 |
+
logger.error("Failed to add safe globals: %s", str(e))
|
| 19 |
+
raise
|
| 20 |
+
|
| 21 |
# Lade YOLOv8-Modell
|
| 22 |
try:
|
| 23 |
logger.info("Loading YOLOv8 model")
|
|
|
|
| 111 |
return {"prompt": prompt, "description": "Error analyzing candles. Try a clearer screenshot with visible candles and prices."}
|
| 112 |
|
| 113 |
else:
|
| 114 |
+
return {"prompt": prompt, "description": "Unsupported prompt. Use 'Was siehst du auf dem Bild?' or 'List last 8 candles with their colors'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|