Add Flask app with Tesseract OCR, dark UI, clipboard paste support

This commit is contained in:
Image-to-Text Agent
2026-04-08 22:57:20 +03:00
parent c7bc131b0a
commit e9be764991
5 changed files with 199 additions and 2 deletions

28
app.py Normal file
View File

@@ -0,0 +1,28 @@
from flask import Flask, request, render_template, flash
from PIL import Image
import pytesseract
import io
app = Flask(__name__)
app.secret_key = 'secret-key-change-in-production'
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
@app.route('/', methods=['GET', 'POST'])
def index():
text = ''
lang = request.form.get('lang', 'eng+rus')
if request.method == 'POST':
file = request.files.get('image')
if file:
try:
img = Image.open(file.stream)
text = pytesseract.image_to_string(img, lang=lang)
if not text.strip():
text = '(пусто или текст не распознан)'
except Exception as e:
text = f'Ошибка: {e}'
return render_template('index.html', text=text, lang=lang)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8118, debug=False)