import gradio as gr
from model import get_results_model
from model import model_
import cv2
IMAGES = 0
def predict_image(image):
global IMAGES
paths = f'images/image_{IMAGES}.jpg'
cv2.imwrite(paths, image)
IMAGES += 1
result = get_results_model(paths, model_)
if result[2] < 0.001:
label_img = 'Unrecognised'
pred_acc = ''
else:
label_img = result[1]
pred_acc = f'Probability: **{(result[2] * 100):.2f} %**'
return result[0], f' Class: **{label_img}** {pred_acc}'
with gr.Blocks() as demo:
gr.Markdown('**MRI Assistant**')
with gr.Row():
with gr.Column():
image_input = gr.Image(label='MRI')
label = gr.Markdown("")
image_output = gr.Image(label='AI results')
image_button = gr.Button("Predict results")
gr.Markdown(r"""
Social:\
*1.* [*Developers*](https://t.me/HenSolaris) \
*2.* [*Telegram bot*](https://t.me/Altsheimer_AI_bot)
""")
image_button.click(predict_image, inputs=image_input, outputs=[image_output, label])
demo.launch()
print('launched!')