Compare commits
	
		
			2 Commits
		
	
	
		
			70c900fc67
			...
			e30d85065d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e30d85065d | |||
| a6cddef761 | 
@ -1,5 +1,5 @@
 | 
			
		||||
[tool.bumpversion]
 | 
			
		||||
current_version = "1.3.41"
 | 
			
		||||
current_version = "1.3.42"
 | 
			
		||||
commit = true
 | 
			
		||||
tag = true
 | 
			
		||||
tag_name = "{new_version}"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										39
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								app.py
									
									
									
									
									
								
							@ -17,13 +17,6 @@ from lib.reqs import (get_urls, get_user_accounts, add_user_account,
 | 
			
		||||
                    delete_user_account, get_stream_names)
 | 
			
		||||
from config import DevelopmentConfig, ProductionConfig
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    from paddleocr import PaddleOCR
 | 
			
		||||
    from PIL import Image
 | 
			
		||||
    import numpy as np
 | 
			
		||||
    OCR_AVAILABLE = True
 | 
			
		||||
except ImportError:
 | 
			
		||||
    OCR_AVAILABLE = False
 | 
			
		||||
 | 
			
		||||
os.environ["OMP_NUM_THREADS"] = "1"
 | 
			
		||||
os.environ["MKL_NUM_THREADS"] = "1"
 | 
			
		||||
@ -52,10 +45,7 @@ except redis.exceptions.ConnectionError as e:
 | 
			
		||||
 | 
			
		||||
cache = Cache(app, config=cache_config)
 | 
			
		||||
 | 
			
		||||
if app.config.get("OCR_ENABLED") and OCR_AVAILABLE:
 | 
			
		||||
    ocr = PaddleOCR(use_angle_cls=True, lang='en')
 | 
			
		||||
else:
 | 
			
		||||
    app.config["OCR_ENABLED"] = False
 | 
			
		||||
app.config["OCR_ENABLED"] = False
 | 
			
		||||
 | 
			
		||||
app.config["SESSION_COOKIE_SECURE"] = not app.config["DEBUG"]
 | 
			
		||||
app.config['SESSION_COOKIE_HTTPONLY'] = True
 | 
			
		||||
@ -213,7 +203,6 @@ def home() -> str:
 | 
			
		||||
            accounts=len(all_accounts),
 | 
			
		||||
            current_month_accounts=filter_accounts_next_30_days(all_accounts),
 | 
			
		||||
            expired_accounts=filter_accounts_expired(all_accounts),
 | 
			
		||||
            ocr_enabled=app.config.get("OCR_ENABLED"),
 | 
			
		||||
        )
 | 
			
		||||
    return render_template("index.html")
 | 
			
		||||
 | 
			
		||||
@ -300,7 +289,6 @@ def add_account() -> Union[Response, str]:
 | 
			
		||||
 | 
			
		||||
    return render_template(
 | 
			
		||||
        "add_account.html",
 | 
			
		||||
        ocr_enabled=app.config.get("OCR_ENABLED"),
 | 
			
		||||
        text_input_enabled=app.config.get("TEXT_INPUT_ENABLED"),
 | 
			
		||||
        shared_text=shared_text
 | 
			
		||||
    )
 | 
			
		||||
@ -345,31 +333,6 @@ def stream_names() -> Union[Response, str]:
 | 
			
		||||
    base_url = app.config["BASE_URL"]
 | 
			
		||||
    return jsonify(get_stream_names(base_url, session["auth_credentials"]))
 | 
			
		||||
 | 
			
		||||
if app.config.get("OCR_ENABLED"):
 | 
			
		||||
    @app.route('/OCRupload', methods=['POST'])
 | 
			
		||||
    def ocr_upload() -> Union[Response, str, Tuple[Response, int]]:
 | 
			
		||||
        """Handles image uploads for OCR processing."""
 | 
			
		||||
        if 'image' not in request.files:
 | 
			
		||||
            return jsonify({"error": "No image file found"}), 400
 | 
			
		||||
        file = request.files['image']
 | 
			
		||||
        try:
 | 
			
		||||
            image = Image.open(file.stream)
 | 
			
		||||
            image_np = np.array(image)
 | 
			
		||||
            result = ocr.ocr(image_np)
 | 
			
		||||
            extracted_text = [line[1][0] for line in result[0]]
 | 
			
		||||
            # Basic validation
 | 
			
		||||
            if len(extracted_text) >= 4:
 | 
			
		||||
                return render_template(
 | 
			
		||||
                    "add_account.html",
 | 
			
		||||
                    username=extracted_text[2],
 | 
			
		||||
                    password=extracted_text[3],
 | 
			
		||||
                    ocr_enabled=True,
 | 
			
		||||
                    text_input_enabled=app.config.get("TEXT_INPUT_ENABLED")
 | 
			
		||||
                )
 | 
			
		||||
            else:
 | 
			
		||||
                return jsonify({"error": "Could not extract required fields from image"}), 400
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            return jsonify({"error": str(e)}), 500
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    app.run(
 | 
			
		||||
 | 
			
		||||
@ -9,12 +9,6 @@ RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
 | 
			
		||||
# Final stage
 | 
			
		||||
FROM python:3.11-slim-bookworm AS final
 | 
			
		||||
 | 
			
		||||
RUN apt-get update && apt-get install -y --no-install-recommends \
 | 
			
		||||
    libgomp1 \
 | 
			
		||||
    libgl1 \
 | 
			
		||||
    libglib2.0-0 \
 | 
			
		||||
 && apt-get clean \
 | 
			
		||||
 && rm -rf /var/lib/apt/lists/*
 | 
			
		||||
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								requirements.txt
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								requirements.txt
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							@ -6,8 +6,7 @@
 | 
			
		||||
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.min.css" />
 | 
			
		||||
    <style>
 | 
			
		||||
        /* Hide the spinner by default */
 | 
			
		||||
        #loadingSpinner,
 | 
			
		||||
        #ocrLoadingSpinner {
 | 
			
		||||
        #loadingSpinner {
 | 
			
		||||
            display: none;
 | 
			
		||||
        }
 | 
			
		||||
    </style>
 | 
			
		||||
@ -50,20 +49,6 @@
 | 
			
		||||
            <span id="buttonText">Add Account</span>
 | 
			
		||||
        </button>
 | 
			
		||||
    </form>
 | 
			
		||||
    {% if ocr_enabled %}
 | 
			
		||||
    <hr>
 | 
			
		||||
    <h2>Load Details Via OCR</h2>
 | 
			
		||||
        <form action="/OCRupload" method="POST" enctype="multipart/form-data" onsubmit="showLoadingOCR()">
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
                <label for="image">Select Image</label>
 | 
			
		||||
                <input type="file" class="form-control-file" id="image" name="image" accept="image/*" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <button type="submit" class="btn btn-success" id="ocrButton">
 | 
			
		||||
                <span class="spinner-border spinner-border-sm" id="ocrLoadingSpinner" role="status" aria-hidden="true"></span>
 | 
			
		||||
                <span id="ocrButtonText">Load Details</span>
 | 
			
		||||
            </button>
 | 
			
		||||
        </form>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
    {% if text_input_enabled %}
 | 
			
		||||
    <hr>
 | 
			
		||||
    <h2>Load Details Via Text</h2>
 | 
			
		||||
@ -82,11 +67,6 @@
 | 
			
		||||
            document.getElementById("loadingSpinner").style.display = "inline-block";
 | 
			
		||||
            document.getElementById("buttonText").textContent = "Working...";
 | 
			
		||||
        }
 | 
			
		||||
        function showLoadingOCR() {
 | 
			
		||||
            document.getElementById("ocrButton").disabled = true;
 | 
			
		||||
            document.getElementById("ocrLoadingSpinner").style.display = "inline-block";
 | 
			
		||||
            document.getElementById("ocrButtonText").textContent = "Processing...";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        document.addEventListener("DOMContentLoaded", function() {
 | 
			
		||||
            var streamInput = document.getElementById("stream");
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user