Download app.py from Subbu1304/billing: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/Subbu1304/billing/resolve/main/app.py
- Command line
-
hf download hf://spaces/Subbu1304/billing/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Subbu1304/billing/resolve/main/app.py
1.15 kB
| from flask import Flask, request, render_template | |
| import pytesseract | |
| from PIL import Image | |
| import os | |
| app = Flask(__name__) | |
| # Define the path for uploaded files | |
| UPLOAD_FOLDER = 'uploads' | |
| app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER | |
| # Make sure the upload folder exists | |
| os.makedirs(UPLOAD_FOLDER, exist_ok=True) | |
| # Route to home page with form | |
| def index(): | |
| return render_template('index.html') | |
| # Route to handle file upload and invoice extraction | |
| def upload_file(): | |
| if 'invoice_image' not in request.files: | |
| return 'No file part' | |
| file = request.files['invoice_image'] | |
| if file.filename == '': | |
| return 'No selected file' | |
| if file: | |
| file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) | |
| file.save(file_path) | |
| # Use pytesseract to extract text from the image | |
| img = Image.open(file_path) | |
| extracted_text = pytesseract.image_to_string(img) | |
| # Return the extracted text | |
| return render_template('index.html', extracted_text=extracted_text) | |
| if __name__ == '__main__': | |
| app.run(debug=True) | |