File size: 1,274 Bytes
fa3f47f 21b9e9a fa3f47f 21b9e9a fa3f47f 424e812 c1d5f45 | 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 44 45 46 47 48 49 50 | import gradio as gr
from ultralytics import YOLO
import cv2
import PIL.Image as Image
import numpy as np
import os
from huggingface_hub import hf_hub_download
import spaces
token = os.getenv("ACE_TOKEN")
repo_id = "LexBwmn/ACE_LAB"
try:
model_path = hf_hub_download(
repo_id=repo_id,
filename="model.pt",
token=token
)
model = YOLO(model_path)
except Exception as e:
print(f"Error loading private model: {e}")
model = None
@spaces.GPU
def predict(img):
global model
if model is None:
return None
try:
img_array = np.array(img)
results = model(img_array, conf=0.466, imgsz=640)
res_plotted = results[0].plot()
res_rgb = cv2.cvtColor(res_plotted, cv2.COLOR_BGR2RGB)
return Image.fromarray(res_rgb)
except Exception as e:
print(f"CRITICAL ERROR DURING SUBMIT: {e}")
return None
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil", label="Upload Brain MRI"),
outputs=gr.Image(type="pil", label="Detection Results"),
title="ACE-V1.1 Lab Test",
description="Secure Inference Test for Brain Tumor Detection."
)
if __name__ == "__main__":
demo.queue(default_concurrency_limit=1)
demo.launch(ssr_mode=False) |