whiteboard / app.py
5m4ck3r's picture
Upload 11 files
d7508be verified
raw
history blame
1.55 kB
import base64
from flask import Flask, request, jsonify, render_template
from io import BytesIO
from maincode import *
import re
app = Flask(__name__)
def calculate(expression):
try:
result = []
for eq in expression:
result.append(eval(eq.replace("=", "")))
print(result)
return result
except Exception as e:
print(f"Error : {e}")
return []
def advanced_calculator(text):
pattern = r'(\d+(?:\s*[+\-*/]\s*\d+)*)\s?='
matches = re.findall(pattern, text)
filtered_expressions = []
for match in matches:
equation = match + '='
remaining_text = text[text.find(equation)+len(equation):].strip()
if remaining_text and remaining_text[0].isdigit():
continue
filtered_expressions.append(equation.replace(" ", "").strip())
return calculate(filtered_expressions)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/whitebai', methods=['POST'])
def whitebai():
data = request.get_json()
image_data = data.get('image')
if not image_data:
return jsonify({'message': 'No image data received'}), 400
image_data = image_data.split(',')[1]
image_bytes = base64.b64decode(image_data)
image_file = BytesIO(image_bytes)
elt = ExtractTextFromImage(image_file)
elt.process_file()
dat = elt.get_text()
return jsonify({'message': advanced_calculator(dat)})
if __name__ == '__main__':
app.run(debug=True)