from flask import Flask, request, jsonify from PIL import Image import pytesseract import re from flask_cors import CORS app = Flask(name) CORS(app) # Enable CORS so frontend can access this API @app.route('/analyze', methods=['POST']) def analyze(): if 'image' not in request.files: return jsonify({'result': 'No file uploaded'}), 400 image = Image.open(request.files['image']) text = pytesseract.image_to_string(image) patterns = { 'Staircase': ['1.2x', '1.4x', '1.8x', '2.1x'], 'Drop Zone': ['1.01x', '1.04x', '1.07x'], 'Rocket Launch': ['1.1x', '1.2x', '1.1x', '30x'], 'Double Big Boom': ['1.3x', '20x', '1.4x', '50x'], 'Sandwich': ['1.1x', '25x', '1.2x'], 'Wave': ['1.2x', '2.5x', '1.4x', '3.0x'], 'Safe Zone': ['1.4x', '1.6x', '1.9x'], 'Twin Peaks': ['20x', '1.5x', '22x'], 'Triple Tap': ['1.4x', '1.7x', '1.6x', '25x'], 'Shadow': ['1.2x', '40x', '1.3x', '38x'], 'Ladder': ['1.1x', '2x', '10x', '1.1x'], 'Fake Out': ['1.2x', '1.4x', '1.5x', '1.03x'] } matched_patterns = [] for name, sequence in patterns.items(): if all(s in text for s in sequence): matched_patterns.append(name) if matched_patterns: return jsonify({'result': 'Matched pattern(s): ' + ', '.join(matched_patterns)}) else: return jsonify({'result': 'No matching pattern found'}) if name == 'main': app.run(debug=True)

Post a Comment

0 Comments