From e9be7649919100f14bec5a8fb7476324097cd9ab Mon Sep 17 00:00:00 2001 From: Image-to-Text Agent Date: Wed, 8 Apr 2026 22:57:20 +0300 Subject: [PATCH] Add Flask app with Tesseract OCR, dark UI, clipboard paste support --- Dockerfile | 19 ++++++ README.md | 2 - app.py | 28 ++++++++ requirements.txt | 3 + templates/index.html | 149 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 Dockerfile delete mode 100644 README.md create mode 100644 app.py create mode 100644 requirements.txt create mode 100644 templates/index.html diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..336cf00 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.11-slim + +RUN apt-get update && apt-get install -y \ + tesseract-ocr \ + tesseract-ocr-rus \ + tesseract-ocr-eng \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY app.py . +COPY templates/ ./templates/ + +EXPOSE 8118 + +CMD ["python", "app.py"] diff --git a/README.md b/README.md deleted file mode 100644 index 32d287a..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# image-to-text - diff --git a/app.py b/app.py new file mode 100644 index 0000000..44c3f31 --- /dev/null +++ b/app.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4d9ad9b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flask +pillow +pytesseract diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..2c33c81 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,149 @@ + + + + + + Image → Text + + + +
+

🖼️ Image to Text

+ +
+
+ + +

или перетащите файл сюда

+
+ +
+ + +
+
+ + {% if text %} +
+

📝 Результат:

+
{{ text }}
+ +
+ {% endif %} +
+ + + +