Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,82 +1,83 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import ObjCharRec
|
3 |
-
from deep_translator import GoogleTranslator
|
4 |
-
import markdown as md
|
5 |
-
import translate_speak
|
6 |
-
import base64
|
7 |
-
|
8 |
-
langs_list = GoogleTranslator().get_supported_languages()
|
9 |
-
langs_dict = GoogleTranslator().get_supported_languages(as_dict=True)
|
10 |
-
|
11 |
-
def encode_image(image_path):
|
12 |
-
with open(image_path, "rb") as image_file:
|
13 |
-
return base64.b64encode(image_file.read()).decode('utf-8')
|
14 |
-
|
15 |
-
# Encode the images
|
16 |
-
github_logo_encoded = encode_image("Images/github-logo.png")
|
17 |
-
linkedin_logo_encoded = encode_image("Images/linkedin-logo.png")
|
18 |
-
website_logo_encoded = encode_image("Images/ai-logo.png")
|
19 |
-
|
20 |
-
usecase_img_encoded = encode_image("Images/UML/Usecase.png")
|
21 |
-
class_img_encoded = encode_image("Images/UML/class.png")
|
22 |
-
object_img_encoded = encode_image("Images/UML/object.png")
|
23 |
-
sequence_img_encoded = encode_image("Images/UML/sequence.png")
|
24 |
-
component_img_encoded = encode_image("Images/UML/component.png")
|
25 |
-
colab_img_encoded = encode_image("Images/UML/colab.png")
|
26 |
-
activity_img_encoded = encode_image("Images/UML/activity.png")
|
27 |
-
|
28 |
-
with gr.Blocks(theme=gr.themes.Ocean(font=[gr.themes.GoogleFont("Noto Sans")]), css='footer {visibility: hidden}') as main_interface:
|
29 |
-
gr.Markdown("# Welcome to The Linguistic Lens 👓🗣️")
|
30 |
-
with gr.Tabs():
|
31 |
-
with gr.TabItem("Intro"):
|
32 |
-
gr.Markdown(md.description)
|
33 |
-
gr.Markdown(md.usecase_diagram.format(usecase_img_encoded))
|
34 |
-
gr.Markdown(md.class_diagram.format(class_img_encoded))
|
35 |
-
gr.Markdown(md.object_diagram.format(object_img_encoded))
|
36 |
-
gr.Markdown(md.sequence_diagram.format(sequence_img_encoded))
|
37 |
-
gr.Markdown(md.colab_diagram.format(colab_img_encoded))
|
38 |
-
gr.Markdown(md.activity_diagram.format(activity_img_encoded))
|
39 |
-
gr.Markdown(md.component_diagram.format(component_img_encoded))
|
40 |
-
|
41 |
-
with gr.TabItem("⭐Translator"):
|
42 |
-
with gr.Row():
|
43 |
-
with gr.Column():
|
44 |
-
with gr.Row():
|
45 |
-
image_input = gr.Image(label="Upload Image")
|
46 |
-
|
47 |
-
with gr.Row():
|
48 |
-
clear_btn = gr.ClearButton()
|
49 |
-
submit_btn = gr.Button("Submit")
|
50 |
-
with gr.Column():
|
51 |
-
with gr.Row():
|
52 |
-
output_text = gr.Text(label="Output")
|
53 |
-
audio_out = gr.Audio(label="Streamed Audio")
|
54 |
-
lang_drop = gr.Dropdown(langs_dict, label="language", interactive=True)
|
55 |
-
translate_btn = gr.Button("Translate")
|
56 |
-
with gr.Row():
|
57 |
-
translated_txt = gr.Text(label="translated text")
|
58 |
-
translated_out = gr.Audio(label="Streamed Audio")
|
59 |
-
|
60 |
-
submit_btn.click(fn=ObjCharRec.ocr_with_paddle, inputs=image_input, outputs=[output_text, audio_out])
|
61 |
-
translate_btn.click(fn=translate_speak.translate_txt, inputs=[lang_drop, output_text],
|
62 |
-
outputs=[translated_txt, translated_out])
|
63 |
-
clear_btn.click(lambda: [None] * 5, outputs=[image_input, output_text, translated_txt, translated_out, audio_out])
|
64 |
-
|
65 |
-
with gr.TabItem("Simple OCR"):
|
66 |
-
gr.Markdown("Paddle OCR")
|
67 |
-
with gr.Row():
|
68 |
-
with gr.Column():
|
69 |
-
image_input = gr.Image(label="Upload Image")
|
70 |
-
with gr.Row():
|
71 |
-
clear_btn = gr.ClearButton()
|
72 |
-
submit_btn = gr.Button("Submit")
|
73 |
-
output_text = gr.Text(label="Output")
|
74 |
-
|
75 |
-
submit_btn.click(fn=ObjCharRec.ocr_with_paddle, inputs=image_input, outputs=output_text)
|
76 |
-
clear_btn.click(lambda :[None]*2, outputs=[image_input, output_text])
|
77 |
-
|
78 |
-
gr.
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import ObjCharRec
|
3 |
+
from deep_translator import GoogleTranslator
|
4 |
+
import markdown as md
|
5 |
+
import translate_speak
|
6 |
+
import base64
|
7 |
+
|
8 |
+
langs_list = GoogleTranslator().get_supported_languages()
|
9 |
+
langs_dict = GoogleTranslator().get_supported_languages(as_dict=True)
|
10 |
+
|
11 |
+
def encode_image(image_path):
|
12 |
+
with open(image_path, "rb") as image_file:
|
13 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
14 |
+
|
15 |
+
# Encode the images
|
16 |
+
github_logo_encoded = encode_image("Images/github-logo.png")
|
17 |
+
linkedin_logo_encoded = encode_image("Images/linkedin-logo.png")
|
18 |
+
website_logo_encoded = encode_image("Images/ai-logo.png")
|
19 |
+
|
20 |
+
usecase_img_encoded = encode_image("Images/UML/Usecase.png")
|
21 |
+
class_img_encoded = encode_image("Images/UML/class.png")
|
22 |
+
object_img_encoded = encode_image("Images/UML/object.png")
|
23 |
+
sequence_img_encoded = encode_image("Images/UML/sequence.png")
|
24 |
+
component_img_encoded = encode_image("Images/UML/component.png")
|
25 |
+
colab_img_encoded = encode_image("Images/UML/colab.png")
|
26 |
+
activity_img_encoded = encode_image("Images/UML/activity.png")
|
27 |
+
|
28 |
+
with gr.Blocks(theme=gr.themes.Ocean(font=[gr.themes.GoogleFont("Noto Sans")]), css='footer {visibility: hidden}') as main_interface:
|
29 |
+
gr.Markdown("# Welcome to The Linguistic Lens 👓🗣️")
|
30 |
+
with gr.Tabs():
|
31 |
+
with gr.TabItem("Intro"):
|
32 |
+
gr.Markdown(md.description)
|
33 |
+
gr.Markdown(md.usecase_diagram.format(usecase_img_encoded))
|
34 |
+
gr.Markdown(md.class_diagram.format(class_img_encoded))
|
35 |
+
gr.Markdown(md.object_diagram.format(object_img_encoded))
|
36 |
+
gr.Markdown(md.sequence_diagram.format(sequence_img_encoded))
|
37 |
+
gr.Markdown(md.colab_diagram.format(colab_img_encoded))
|
38 |
+
gr.Markdown(md.activity_diagram.format(activity_img_encoded))
|
39 |
+
gr.Markdown(md.component_diagram.format(component_img_encoded))
|
40 |
+
|
41 |
+
with gr.TabItem("⭐Translator"):
|
42 |
+
with gr.Row():
|
43 |
+
with gr.Column():
|
44 |
+
with gr.Row():
|
45 |
+
image_input = gr.Image(label="Upload Image")
|
46 |
+
|
47 |
+
with gr.Row():
|
48 |
+
clear_btn = gr.ClearButton()
|
49 |
+
submit_btn = gr.Button("Submit")
|
50 |
+
with gr.Column():
|
51 |
+
with gr.Row():
|
52 |
+
output_text = gr.Text(label="Output")
|
53 |
+
audio_out = gr.Audio(label="Streamed Audio")
|
54 |
+
lang_drop = gr.Dropdown(langs_dict, label="language", interactive=True)
|
55 |
+
translate_btn = gr.Button("Translate")
|
56 |
+
with gr.Row():
|
57 |
+
translated_txt = gr.Text(label="translated text")
|
58 |
+
translated_out = gr.Audio(label="Streamed Audio")
|
59 |
+
|
60 |
+
submit_btn.click(fn=ObjCharRec.ocr_with_paddle, inputs=image_input, outputs=[output_text, audio_out])
|
61 |
+
translate_btn.click(fn=translate_speak.translate_txt, inputs=[lang_drop, output_text],
|
62 |
+
outputs=[translated_txt, translated_out])
|
63 |
+
clear_btn.click(lambda: [None] * 5, outputs=[image_input, output_text, translated_txt, translated_out, audio_out])
|
64 |
+
|
65 |
+
with gr.TabItem("Simple OCR"):
|
66 |
+
gr.Markdown("Paddle OCR")
|
67 |
+
with gr.Row():
|
68 |
+
with gr.Column():
|
69 |
+
image_input = gr.Image(label="Upload Image")
|
70 |
+
with gr.Row():
|
71 |
+
clear_btn = gr.ClearButton()
|
72 |
+
submit_btn = gr.Button("Submit")
|
73 |
+
output_text = gr.Text(label="Output")
|
74 |
+
|
75 |
+
submit_btn.click(fn=ObjCharRec.ocr_with_paddle, inputs=image_input, outputs=output_text)
|
76 |
+
clear_btn.click(lambda :[None]*2, outputs=[image_input, output_text])
|
77 |
+
|
78 |
+
gr.HTML(md.footer.format(github_logo_encoded, linkedin_logo_encoded, website_logo_encoded))
|
79 |
+
# gr.Markdown(md.footer.format(github_logo_encoded, linkedin_logo_encoded, website_logo_encoded))
|
80 |
+
|
81 |
+
|
82 |
+
if __name__ == "__main__":
|
83 |
+
main_interface.launch()
|