| import gradio as gr |
| from fastai.vision.all import * |
| from huggingface_hub import from_pretrained_fastai |
| import platform |
| import pathlib |
| import sys |
|
|
| |
| if platform.system() != 'Windows': |
| pathlib.WindowsPath = pathlib.PosixPath |
|
|
| |
| |
| |
| try: |
| import plum |
| sys.modules['plum.function'] = plum |
| except ImportError: |
| pass |
|
|
| |
| repo_id = "alperema/practica1-neumonia" |
| learner = from_pretrained_fastai(repo_id) |
| labels = learner.dls.vocab |
|
|
| def predict(img): |
| img = PILImage.create(img) |
| pred, pred_idx, probs = learner.predict(img) |
| return {labels[i]: float(probs[i]) for i in range(len(labels))} |
|
|
| gr.Interface( |
| fn=predict, |
| inputs=gr.Image(), |
| outputs=gr.Label(num_top_classes=2), |
| examples=['normal.jpeg', 'neumonia.jpeg'] |
| ).launch() |