-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (29 loc) · 1.05 KB
/
app.py
File metadata and controls
38 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import tempfile
from flask import Flask, render_template, request, redirect, url_for
from werkzeug.utils import secure_filename
import pytesseract
import pyttsx3
from PIL import Image
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def home():
return render_template("home.html")
@app.route("/", methods=["POST"])
def upload_image():
# Get the uploaded image file from the form
image = request.files["image"]
# Save the image file to a temporary directory
image_path = os.path.join(tempfile.gettempdir(), secure_filename(image.filename))
image.save(image_path)
# Use Tesseract OCR to extract the text from the image
text = pytesseract.image_to_string(Image.open(image_path))
# Use pyttsx3 to speak the extracted text
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
# Render the result template with the extracted text
return render_template("result.html", text=text)
if __name__ == "__main__":
app.run(debug=True)