krplt's picture
feat: update
6ebde35
raw
history blame contribute delete
No virus
1.19 kB
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()