Arjooohn commited on
Commit
1b65d81
·
verified ·
1 Parent(s): 68aa0d9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pytesseract
3
+ import cv2
4
+ import numpy as np
5
+ from PIL import Image
6
+ from gtts import gTTS
7
+ import os
8
+
9
+ def preprocess(image):
10
+ img = np.array(image)
11
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12
+ blur = cv2.GaussianBlur(gray, (5,5), 0)
13
+ thresh = cv2.threshold(
14
+ blur, 0, 255,
15
+ cv2.THRESH_BINARY + cv2.THRESH_OTSU
16
+ )[1]
17
+ return thresh
18
+
19
+ def extract_and_speak(image):
20
+ processed = preprocess(image)
21
+
22
+ text = pytesseract.image_to_string(processed, lang="eng")
23
+
24
+ if text.strip() == "":
25
+ return "No readable text found.", None
26
+
27
+ tts = gTTS(text)
28
+ tts.save("output.mp3")
29
+
30
+ return text, "output.mp3"
31
+
32
+ interface = gr.Interface(
33
+ fn=extract_and_speak,
34
+ inputs=gr.Image(type="pil"),
35
+ outputs=[
36
+ gr.Textbox(label="Extracted Text"),
37
+ gr.Audio(label="Text-to-Speech Output")
38
+ ],
39
+ title="GabAI - AI Assistive Reading System",
40
+ description="Upload an image containing printed text. The system extracts the text and converts it into speech."
41
+ )
42
+
43
+ interface.launch()