Spaces:
Runtime error
Runtime error
##importing the libraries | |
import torch | |
import cv2 | |
import os | |
import numpy as np | |
import pandas as pd | |
import gradio as gr | |
from ultralytics import YOLO | |
# Load your trained model | |
model = YOLO('best.pt') | |
### Preprocess the new image | |
def predict_image(test_image): | |
# save images | |
model.predict(test_image, save=True, conf=0.1, batch=2) | |
path = "runs\\detect" | |
detection = (os.listdir(path)) | |
def extract_digits(x): | |
digits = ''.join(filter(str.isdigit, x)) | |
return int(digits) if digits else float('inf') #Use float('inf') as a default value | |
sorted_ = sorted(detection, key=extract_digits) | |
if len(sorted_)>1: | |
latest_detection = sorted_[-2] # | |
else: | |
latest_detection = sorted_[0] | |
detection_path = os.path.join(path, latest_detection) | |
pred = cv2.imread(os.path.join(detection_path, test_image)) | |
return pred | |
platform = gr.Interface( fn = predict_image, | |
title ="PTCADx: Computer-Aided Detection of Pneumothorax in Chest X-ray Images", | |
inputs = "image", | |
outputs = "image", | |
description=""" | |
Introducing a revolutionary computer-aided detection tool designed to enhance the efficiency of clinicians in detecting pneumothorax in chest X-ray images. | |
""", | |
article = """ | |
It is crucial to emphasize that while this tool serves as a valuable research aid, | |
it is not intended to replace clinical guidelines, | |
nor should it substitute for the wealth of clinical knowledge | |
and experience possessed by healthcare professionals. | |
The algorithm is meant to complement and support the diagnostic process, | |
providing an additional layer of analysis for consideration in conjunction with the clinician's expertise. | |
Users are encouraged to interpret the algorithm's output in conjunction with their clinical judgment, | |
and the tool should be viewed as a supplementary resource rather than a standalone diagnostic solution. | |
""" ) | |
platform.launch(inline=True,share=True) |