Add Flask app with Tesseract OCR, dark UI, clipboard paste support
This commit is contained in:
28
app.py
Normal file
28
app.py
Normal 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)
|
||||
Reference in New Issue
Block a user