File size: 2,313 Bytes
d69917c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import gradio as gr
import ObjCharRec
from deep_translator import GoogleTranslator

import demo_app
import translate_speak

langs_list = GoogleTranslator().get_supported_languages()
langs_dict = GoogleTranslator().get_supported_languages(as_dict=True)

with gr.Blocks() as main_interface:
    gr.Markdown("# OCR")
    with gr.Tabs():
        with gr.TabItem("Intro"):
            pass

        with gr.TabItem("Simple OCR"):
            gr.Markdown("Paddle OCR")
            with gr.Row():
                with gr.Column():
                    image_input = gr.Image(label="Upload Image")
                    with gr.Row():
                        clear_btn = gr.ClearButton()
                        submit_btn = gr.Button("Submit")
                output_text = gr.Text(label="Output")

            submit_btn.click(fn=ObjCharRec.ocr_with_paddle, inputs=image_input, outputs=output_text)
            clear_btn.click(lambda :[None, None], outputs=[image_input, output_text])

        with gr.TabItem("translator"):
            with gr.Row():
                with gr.Column():
                    image_input = gr.Image(label="Upload Image")
                    with gr.Row():
                        clear_btn = gr.ClearButton()
                        submit_btn = gr.Button("Submit")
                with gr.Column():
                    with gr.Row():
                        output_text = gr.Text(label="Output")
                        audio_out = gr.Audio(label="Streamed Audio")
                    lang_drop = gr.Dropdown(langs_dict, label="language",  interactive=True)
                    translate_btn = gr.Button("Translate")
                    with gr.Row():
                        translated_txt = gr.Text(label="translated text")
                        translated_out = gr.Audio(label="Streamed Audio")


            submit_btn.click(fn=ObjCharRec.ocr_with_paddle, inputs=image_input, outputs=[output_text, audio_out])
            translate_btn.click(fn=translate_speak.translate_txt, inputs=[lang_drop, output_text], outputs=[translated_txt, translated_out])
            clear_btn.click(lambda :[None]*5, outputs=[image_input, output_text, translated_txt, translated_out, audio_out])

if __name__ == "__main__":
    main_interface.launch()