File size: 1,192 Bytes
6ebde35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from services import ocr_with_paddle, solve_with_transformers


def solve_math(img):
    """
    Perform optical character recognition on the input image and then solve the extracted text using 🤗transformers.

    :param img: The input image for optical character recognition.
    :return: The solved text answer.
    """
    try:
        text_output = ocr_with_paddle(img['composite'])
        text_answer = solve_with_transformers(text_output)

        return text_answer
    except Exception:
        raise gr.Error("Please upload an image!!!!")


"""
Create user interface
"""


def main():
    with gr.Blocks() as app:
        gr.Markdown("### Калькулятор комплексных чисел")
        with gr.Row():
            with gr.Column():
                image_input = gr.ImageEditor(value='canvas.png', image_mode='L', interactive=True, type='filepath')
                process_btn = gr.Button('Решить')
            with gr.Column():
                output_text = gr.Textbox(label="Решение")

        process_btn.click(fn=solve_math, inputs=image_input, outputs=output_text)

    app.launch()


if __name__ == "__main__":
    main()