Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,13 @@ import torch
|
|
10 |
import torchaudio
|
11 |
import gradio as gr
|
12 |
import torchaudio.transforms as T
|
13 |
-
import easyocr
|
14 |
import polars as pl
|
15 |
|
16 |
from importlib.metadata import version
|
17 |
from gradio.utils import is_zero_gpu_space
|
18 |
from gradio.themes import Base
|
19 |
|
|
|
20 |
from transformers import (
|
21 |
AutoModelForCausalLM,
|
22 |
AutoTokenizer,
|
@@ -67,7 +67,12 @@ audio_model = AutoModelForCTC.from_pretrained(
|
|
67 |
processor = Wav2Vec2BertProcessor.from_pretrained("Yehor/w2v-bert-uk-v2.1-bf16")
|
68 |
|
69 |
# Load OCR
|
70 |
-
ocr_model =
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
# Examples
|
73 |
examples_text = [
|
@@ -299,7 +304,12 @@ def inference_image(image, progress=gr.Progress()):
|
|
299 |
if not isinstance(image, str):
|
300 |
raise gr.Error("Please paste your image file.")
|
301 |
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
303 |
text = " ".join(results)
|
304 |
|
305 |
print("Text:", text)
|
|
|
10 |
import torchaudio
|
11 |
import gradio as gr
|
12 |
import torchaudio.transforms as T
|
|
|
13 |
import polars as pl
|
14 |
|
15 |
from importlib.metadata import version
|
16 |
from gradio.utils import is_zero_gpu_space
|
17 |
from gradio.themes import Base
|
18 |
|
19 |
+
from paddleocr import PaddleOCR
|
20 |
from transformers import (
|
21 |
AutoModelForCausalLM,
|
22 |
AutoTokenizer,
|
|
|
67 |
processor = Wav2Vec2BertProcessor.from_pretrained("Yehor/w2v-bert-uk-v2.1-bf16")
|
68 |
|
69 |
# Load OCR
|
70 |
+
ocr_model = PaddleOCR(
|
71 |
+
lang="uk",
|
72 |
+
use_doc_orientation_classify=False,
|
73 |
+
use_doc_unwarping=False,
|
74 |
+
use_textline_orientation=False,
|
75 |
+
)
|
76 |
|
77 |
# Examples
|
78 |
examples_text = [
|
|
|
304 |
if not isinstance(image, str):
|
305 |
raise gr.Error("Please paste your image file.")
|
306 |
|
307 |
+
predictions = ocr_model.predict(image)
|
308 |
+
|
309 |
+
results = []
|
310 |
+
for prediction in predictions:
|
311 |
+
results.append(' '.join(prediction['rec_texts']))
|
312 |
+
|
313 |
text = " ".join(results)
|
314 |
|
315 |
print("Text:", text)
|