gahanmakwana commited on
Commit
93c87da
ยท
0 Parent(s):

Initial clean commit

Browse files
Files changed (10) hide show
  1. .gitattributes +7 -0
  2. .gitignore +10 -0
  3. app.py +42 -0
  4. bfg-1.15.0.jar +3 -0
  5. render.yaml +10 -0
  6. require.txt +10 -0
  7. requirements.txt +3 -0
  8. run_ocr.py +8 -0
  9. static/style.css +71 -0
  10. templates/index.html +37 -0
.gitattributes ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ *.dll filter=lfs diff=lfs merge=lfs -text
2
+ *.pyd filter=lfs diff=lfs merge=lfs -text
3
+ *.jar filter=lfs diff=lfs merge=lfs -text
4
+ *.ttf filter=lfs diff=lfs merge=lfs -text
5
+ *.pdiparams filter=lfs diff=lfs merge=lfs -text
6
+ *.pdmodel filter=lfs diff=lfs merge=lfs -text
7
+ *.info filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ venv/
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.pyd
6
+ *.db
7
+ *.sqlite3
8
+ uploads/
9
+ .env
10
+ .DS_Store
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import sys
2
+ # import os
3
+ # sys.path.insert(0, os.path.abspath("C:\Users\KRUNAL\Desktop\my_ocr_project\PaddleOCR"))
4
+
5
+ from flask import Flask, render_template, request, send_from_directory
6
+ import os
7
+ from paddleocr import PaddleOCR
8
+
9
+ app = Flask(__name__)
10
+ UPLOAD_FOLDER = 'uploads'
11
+ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
12
+
13
+ ocr = PaddleOCR(use_angle_cls=True, lang='en')
14
+
15
+ @app.route('/', methods=['GET', 'POST'])
16
+ def upload_file():
17
+ text = None
18
+ filename = None
19
+ if request.method == 'POST':
20
+ file = request.files['file']
21
+ if file:
22
+ filename = file.filename
23
+ img_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
24
+ file.save(img_path)
25
+
26
+ # Run OCR
27
+ result = ocr.ocr(img_path, cls=True)
28
+ extracted_text = ""
29
+ for line in result:
30
+ for word_info in line:
31
+ extracted_text += word_info[1][0] + " "
32
+
33
+ text = extracted_text
34
+
35
+ return render_template('index.html', text=text, filename=filename)
36
+
37
+ @app.route('/uploads/<filename>')
38
+ def uploaded_file(filename):
39
+ return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
40
+
41
+ if __name__ == '__main__':
42
+ app.run(debug=True)
bfg-1.15.0.jar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfe2885adc2916379093f02a80181200536856c9a987bf21c492e452adefef7a
3
+ size 14721936
render.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ - type: web
3
+ name: ocr-app
4
+ env: python
5
+ plan: free
6
+ buildCommand: pip install -r requirements.txt
7
+ startCommand: python app.py
8
+ envVars:
9
+ - key: PORT
10
+ value: 5000
require.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ shapely==2.1.0
2
+ scikit-image==0.18.3
3
+ imgaug==0.4.0
4
+ pyclipper
5
+ lmdb
6
+ tqdm
7
+ numpy
8
+ visualdl
9
+ python-Levenshtein
10
+ opencv-contrib-python==4.5.5.62
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask
2
+ paddleocr
3
+ paddlepaddle
run_ocr.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from paddleocr import PaddleOCR
2
+
3
+ ocr = PaddleOCR(use_angle_cls=True, lang='en', use_gpu=False)
4
+ img_path = r"C:\Users\KRUNAL\OneDrive\Pictures\Camera imports\2024-08-22 (2)\1000015730.jpg"
5
+ result = ocr.ocr(img_path, cls=True)
6
+
7
+ print(result)
8
+
static/style.css ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: 'Poppins', sans-serif;
3
+ background: linear-gradient(135deg, #74ebd5, #acb6e5);
4
+ text-align: center;
5
+ padding: 30px;
6
+ }
7
+
8
+ .container {
9
+ background: white;
10
+ border-radius: 16px;
11
+ box-shadow: 0px 10px 30px rgba(0,0,0,0.2);
12
+ padding: 40px;
13
+ display: inline-block;
14
+ max-width: 700px;
15
+ animation: fadeIn 1s ease-in;
16
+ }
17
+
18
+ h1 {
19
+ margin-bottom: 20px;
20
+ color: #333;
21
+ }
22
+
23
+ .custom-file-upload {
24
+ background-color: #007bff;
25
+ border: none;
26
+ color: white;
27
+ padding: 14px 28px;
28
+ border-radius: 8px;
29
+ cursor: pointer;
30
+ font-size: 18px;
31
+ transition: background 0.3s;
32
+ }
33
+
34
+ .custom-file-upload:hover {
35
+ background-color: #0056b3;
36
+ }
37
+
38
+ input[type="file"] {
39
+ display: none;
40
+ }
41
+
42
+ .image-preview {
43
+ margin-top: 30px;
44
+ }
45
+
46
+ .image-preview img {
47
+ width: 100%;
48
+ max-height: 400px;
49
+ object-fit: contain;
50
+ border-radius: 12px;
51
+ margin-top: 10px;
52
+ box-shadow: 0 5px 15px rgba(0,0,0,0.2);
53
+ }
54
+
55
+ .output-box {
56
+ margin-top: 30px;
57
+ background: #f0f0f0;
58
+ padding: 20px;
59
+ border-radius: 10px;
60
+ text-align: left;
61
+ word-wrap: break-word;
62
+ }
63
+
64
+ .output-box p {
65
+ white-space: pre-wrap;
66
+ }
67
+
68
+ @keyframes fadeIn {
69
+ from { opacity: 0; transform: translateY(30px); }
70
+ to { opacity: 1; transform: translateY(0); }
71
+ }
templates/index.html ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>OCR App</title>
6
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
7
+ </head>
8
+ <body>
9
+
10
+ <div class="container">
11
+ <h1>๐Ÿ“ OCR Text Recognition</h1>
12
+
13
+ <form method="POST" enctype="multipart/form-data">
14
+ <label for="file-upload" class="custom-file-upload">
15
+ ๐Ÿ“‚ Choose an image
16
+ </label>
17
+ <input id="file-upload" type="file" name="file" onchange="this.form.submit()" />
18
+ </form>
19
+
20
+ {% if filename %}
21
+ <div class="image-preview">
22
+ <h2>๐Ÿ–ผ Uploaded Image:</h2>
23
+ <img src="{{ url_for('uploaded_file', filename=filename) }}" alt="Uploaded Image">
24
+ </div>
25
+ {% endif %}
26
+
27
+ {% if text %}
28
+ <div class="output-box">
29
+ <h2>๐Ÿ“‹ Extracted Text:</h2>
30
+ <p>{{ text }}</p>
31
+ </div>
32
+ {% endif %}
33
+
34
+ </div>
35
+
36
+ </body>
37
+ </html>