Spaces:
Running
Running
Commit
·
98bb570
1
Parent(s):
37e0465
Fixed file upload and OCR functionality
Browse files- app.py +2 -1
- templates/index.html +10 -14
app.py
CHANGED
@@ -6,6 +6,7 @@ app = Flask(__name__)
|
|
6 |
|
7 |
# Create uploads directory if it doesn't exist
|
8 |
UPLOAD_FOLDER = 'uploads'
|
|
|
9 |
if not os.path.exists(UPLOAD_FOLDER):
|
10 |
os.makedirs(UPLOAD_FOLDER)
|
11 |
|
@@ -40,7 +41,7 @@ def upload_file():
|
|
40 |
|
41 |
return render_template('index.html')
|
42 |
|
43 |
-
# Serve the uploaded file
|
44 |
@app.route('/uploads/<filename>')
|
45 |
def uploaded_file(filename):
|
46 |
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
|
|
|
6 |
|
7 |
# Create uploads directory if it doesn't exist
|
8 |
UPLOAD_FOLDER = 'uploads'
|
9 |
+
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER # Set the uploads folder in app config
|
10 |
if not os.path.exists(UPLOAD_FOLDER):
|
11 |
os.makedirs(UPLOAD_FOLDER)
|
12 |
|
|
|
41 |
|
42 |
return render_template('index.html')
|
43 |
|
44 |
+
# Serve the uploaded file (from the uploads directory)
|
45 |
@app.route('/uploads/<filename>')
|
46 |
def uploaded_file(filename):
|
47 |
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
|
templates/index.html
CHANGED
@@ -3,21 +3,20 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>OCR
|
7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/css/bootstrap.min.css">
|
8 |
-
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
9 |
</head>
|
10 |
<body>
|
11 |
<div class="container mt-5">
|
12 |
-
<h1
|
13 |
|
14 |
<!-- Form to upload file -->
|
15 |
-
<form method="post" enctype="multipart/form-data"
|
16 |
-
<div class="
|
17 |
-
<label for="file" class="
|
18 |
-
<input type="file" name="file" id="file" required
|
19 |
</div>
|
20 |
-
<button type="submit" class="btn btn-primary
|
21 |
</form>
|
22 |
|
23 |
<!-- Error Message Display -->
|
@@ -30,19 +29,16 @@
|
|
30 |
<!-- Display OCR Result -->
|
31 |
{% if text %}
|
32 |
<h3 class="mt-4">Extracted Text:</h3>
|
33 |
-
<
|
34 |
-
<pre>{{ text }}</pre>
|
35 |
-
</div>
|
36 |
{% endif %}
|
37 |
|
38 |
-
<!-- Display Uploaded Image -->
|
39 |
{% if filename %}
|
40 |
-
<h4
|
41 |
<img src="{{ url_for('uploaded_file', filename=filename) }}" alt="Uploaded Image" class="img-fluid mt-3">
|
42 |
{% endif %}
|
43 |
</div>
|
44 |
|
45 |
-
<!-- Optional: Bootstrap JavaScript for interaction -->
|
46 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/js/bootstrap.bundle.min.js"></script>
|
47 |
</body>
|
48 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>OCR App</title>
|
7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/css/bootstrap.min.css">
|
|
|
8 |
</head>
|
9 |
<body>
|
10 |
<div class="container mt-5">
|
11 |
+
<h1>OCR Application</h1>
|
12 |
|
13 |
<!-- Form to upload file -->
|
14 |
+
<form method="post" enctype="multipart/form-data">
|
15 |
+
<div class="mb-3">
|
16 |
+
<label for="file" class="form-label">Choose a file</label>
|
17 |
+
<input type="file" class="form-control" name="file" id="file" required>
|
18 |
</div>
|
19 |
+
<button type="submit" class="btn btn-primary">Upload</button>
|
20 |
</form>
|
21 |
|
22 |
<!-- Error Message Display -->
|
|
|
29 |
<!-- Display OCR Result -->
|
30 |
{% if text %}
|
31 |
<h3 class="mt-4">Extracted Text:</h3>
|
32 |
+
<pre>{{ text }}</pre>
|
|
|
|
|
33 |
{% endif %}
|
34 |
|
|
|
35 |
{% if filename %}
|
36 |
+
<h4>Uploaded Image:</h4>
|
37 |
<img src="{{ url_for('uploaded_file', filename=filename) }}" alt="Uploaded Image" class="img-fluid mt-3">
|
38 |
{% endif %}
|
39 |
</div>
|
40 |
|
41 |
+
<!-- Optional: Bootstrap JavaScript for interaction (such as form validation) -->
|
42 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/js/bootstrap.bundle.min.js"></script>
|
43 |
</body>
|
44 |
</html>
|