Spaces:
Sleeping
Sleeping
Fix bugs
Browse files
app.py
CHANGED
|
@@ -4,7 +4,8 @@ import numpy as np
|
|
| 4 |
from PIL import Image
|
| 5 |
import pytesseract
|
| 6 |
from gtts import gTTS
|
| 7 |
-
import
|
|
|
|
| 8 |
|
| 9 |
def preprocess(image):
|
| 10 |
img = np.array(image)
|
|
@@ -30,11 +31,10 @@ def extract_text_and_speak(image):
|
|
| 30 |
|
| 31 |
# Create TTS only if text exists
|
| 32 |
if text and text != "No readable text found.":
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
audio_file = buffer
|
| 38 |
else:
|
| 39 |
audio_file = None
|
| 40 |
if not text:
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import pytesseract
|
| 6 |
from gtts import gTTS
|
| 7 |
+
import tempfile
|
| 8 |
+
import os
|
| 9 |
|
| 10 |
def preprocess(image):
|
| 11 |
img = np.array(image)
|
|
|
|
| 31 |
|
| 32 |
# Create TTS only if text exists
|
| 33 |
if text and text != "No readable text found.":
|
| 34 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmpfile:
|
| 35 |
+
tts = gTTS(text)
|
| 36 |
+
tts.save(tmpfile.name)
|
| 37 |
+
audio_file = tmpfile.name
|
|
|
|
| 38 |
else:
|
| 39 |
audio_file = None
|
| 40 |
if not text:
|