Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line2345678910115 unmodified lines1718192021226 unmodified lines293031323334353637383940411 unmodified lineimport pytesseractimport cv2import numpy as npfrom gtts import gTTSdef preprocess(image):# Convert to grayscale, blur, threshold; no flippingimg = np.array(image)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)blur = cv2.GaussianBlur(gray, (5,5), 0)5 unmodified linesdef extract_and_speak(image):processed = preprocess(image)text = pytesseract.image_to_string(processed, lang="eng")if text.strip() == "":6 unmodified linesinterface = gr.Interface(fn=extract_and_speak,inputs=gr.Image(type="pil", sources=["webcam"]), # Webcam preview mirrored by defaultoutputs=[gr.Textbox(label="Extracted Text"),gr.Audio(label="Text-to-Speech Output")],title="GabAI - AI Assistive Reading System",description="Use your webcam to capture printed text. Preview is mirrored, but captured image is normal for OCR.")interface.launch()1 unmodified line234567891011125 unmodified lines181920212223246 unmodified lines313233343536373839404142431 unmodified lineimport pytesseractimport cv2import numpy as npfrom PIL import Imagefrom gtts import gTTSimport osdef preprocess(image):img = np.array(image)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)blur = cv2.GaussianBlur(gray, (5,5), 0)5 unmodified linesdef extract_and_speak(image):processed = preprocess(image)text = pytesseract.image_to_string(processed, lang="eng")if text.strip() == "":6 unmodified linesinterface = gr.Interface(fn=extract_and_speak,inputs=gr.Image(type="pil", source="webcam", tool=None), # Only webcam, no upload/pasteoutputs=[gr.Textbox(label="Extracted Text"),gr.Audio(label="Text-to-Speech Output")],title="GabAI - AI Assistive Reading System",description="Use your webcam to capture printed text. The system extracts the text and converts it into speech.")interface.launch()
app.py+5-3