Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from fastai.vision.all import * | |
| from PIL import Image | |
| import io | |
| import numpy as np | |
| learn = load_learner('model.pkl') | |
| labels = learn.dls.vocab | |
| input_shape = (512, 512) # Dimensões desejadas para a entrada | |
| def preprocess_image(img): | |
| img = Image.fromarray(np.uint8(img)) | |
| img = img.resize(input_shape) | |
| return img | |
| def predict(img): | |
| img = preprocess_image(img) | |
| img = PILImage.create(img) | |
| pred, pred_idx, probs = learn.predict(img) | |
| return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
| title = "Tuberculosis detector" | |
| description = "A tuberculosis detector trained on 3700 chest X-ray images. Created as a demo for Gradio and HuggingFace Spaces." | |
| examples = ['1.jpeg', '2.jpeg', '3.jpeg', '4.jpeg'] | |
| interpretation = 'default' | |
| enable_queue = True | |
| gr.Interface(fn=predict, inputs=gr.inputs.Image(), outputs=gr.outputs.Label(num_top_classes=2), | |
| title=title, description=description, interpretation=interpretation, | |
| examples=examples, enable_queue=enable_queue).launch() | |