wb-droid commited on
Commit
e37c35c
1 Parent(s): d30ffeb

First commit.

Browse files
Files changed (4) hide show
  1. SpellingList3.jpg +0 -0
  2. SpellingTest8.jpg +0 -0
  3. app.py +81 -0
  4. requirements.txt +4 -0
SpellingList3.jpg ADDED
SpellingTest8.jpg ADDED
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from paddleocr import PaddleOCR, draw_ocr
3
+ import asyncio
4
+ import edge_tts
5
+
6
+ def image2Text(image:str, langChoice:str):
7
+ ocr = PaddleOCR(use_angle_cls=True, lang=langChoice) # need to run only once to download and load model into memory
8
+ img_path = image
9
+ result = ocr.ocr(img_path, cls=True)
10
+ text = ""
11
+ for idx in range(len(result)):
12
+ res = result[idx]
13
+ for line in res:
14
+ import re
15
+ # remove pinyin if it's Chinese
16
+ if langChoice=="ch":
17
+ #t = re.sub('[a-z0-9.]', '', line[1][0])
18
+ t = re.sub('[a-z]', '', line[1][0])
19
+ t = re.sub('[0-9]\.', '', t)
20
+ t = t.replace(" ", "")
21
+ t = t.replace("()", "")
22
+ t = t.replace("()", "")
23
+ t = t.replace("( )", "")
24
+ t = t.replace("()", "")
25
+ if t!="":
26
+ text +=((t) + "\n")
27
+ else:
28
+ t = line[1][0]
29
+ t = re.sub('Term [0-9] Spelling', '', t)
30
+ t = re.sub('Page [0-9]', '', t)
31
+ if t!="":
32
+ text += (t + "\n")
33
+ return text
34
+
35
+
36
+ def text2Voice(recognized_text, langChoice:str):
37
+ async def amain() -> None:
38
+ """Main function"""
39
+ communicate = edge_tts.Communicate(TEXT, VOICE)
40
+ await communicate.save(OUTPUT_FILE)
41
+ TEXT = recognized_text
42
+ if langChoice == "ch":
43
+ VOICE = "zh-CN-YunxiaNeural"
44
+ else:
45
+ VOICE = "en-GB-LibbyNeural"
46
+ OUTPUT_FILE = "voice.mp3"
47
+ #await amain()
48
+ asyncio.run(amain())
49
+ return "voice.mp3"
50
+
51
+ with gr.Blocks() as demo:
52
+ gr.HTML("""<h1 align="center">Spelling Tester</h1>""")
53
+
54
+ examples = ['SpellingList3.jpg']
55
+
56
+ with gr.Row():
57
+ with gr.Column(scale=1):
58
+ upload_image = gr.Image(height=400,width=400, value = "SpellingTest8.jpg")
59
+ #langDrop = gr.Dropdown(
60
+ # ["ch", "en"], label="Language", info="specify the language will help to increase accuracy.", value = "ch"
61
+ #),
62
+ langChoice = gr.Textbox(value="ch", label="Select lanaguage: 'ch' for Chinese, 'en' for English")
63
+ with gr.Column(scale=3):
64
+ recognized_text = gr.Textbox(show_label=False, placeholder="spelling list", lines=15)
65
+ toText = gr.Button("Convert image to text")
66
+
67
+ generated_voice = gr.Audio()
68
+ toVoice = gr.Button("Convert text to voice", variant="primary")
69
+
70
+
71
+ toText.click(
72
+ image2Text,
73
+ [upload_image, langChoice],
74
+ [recognized_text],
75
+ #show_progress=True,
76
+
77
+ )
78
+ toVoice.click(text2Voice, [recognized_text, langChoice], [generated_voice])
79
+
80
+ #searchBtn.click(search, inputs=[user_input], outputs=[search_result], show_progress=True)
81
+ demo.queue().launch(share=False, inbrowser=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ edge-tts
3
+ paddlepaddle
4
+ paddleocr