Spaces:
Sleeping
Sleeping
import gradio as gr | |
from fastai.vision.all import * | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from transformers import pipeline | |
from huggingface_hub import from_pretrained_fastai | |
pipe = pipeline( | |
task="image-classification", | |
model ="ethanmac/dr-maclboomber-retina-classifier", | |
description="Retinal Condition Classifier", | |
examples=['sick-eye.jpeg', 'healthy.jpg'] | |
).launch() | |
# from huggingface_hub import from_pretrained_fastai | |
# # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME" | |
# repo_id = "espejelomar/identify-my-cat" | |
# learner = from_pretrained_fastai(repo_id) | |
# # Load your trained FastAI model | |
# learn = load_learner('export.pkl') | |
# def predict_and_plot(img): | |
# # Get predictions | |
# pred, pred_idx, probs = learn.predict(img) | |
# # Get class names | |
# class_names = ['Normal', | |
# 'Hollenhorst Emboli', | |
# 'Hypertensive Retinopathy', | |
# 'Coat\'s', | |
# 'Macroaneurism', | |
# 'Choroidal Neovascularization', | |
# 'Other', | |
# 'Branch Retinal Artery Occlusion', | |
# 'Cilio-Retinal Artery Occlusion', | |
# 'Branch Retinal Vein Occlusion', | |
# 'Central Retinal Vein Occlusion', | |
# 'Hemi-Central Retinal Vein Occlusion', | |
# 'Background Diabetic Retinopathy', | |
# 'Proliferative Diabetic Retinopathy', | |
# 'Arteriosclerotic Retinopathy'] | |
# probs_np = probs.numpy() | |
# threshold = 0.5 | |
# present = probs_np > threshold | |
# fig, ax = plt.subplots(figsize=(10, 6)) | |
# y_pos = np.arange(len(class_names)) | |
# colors = ['green' if is_present else 'red' for is_present in present] | |
# ax.barh(y_pos, probs_np, color=colors) | |
# ax.set_yticks(y_pos) | |
# ax.set_yticklabels(class_names) | |
# ax.invert_yaxis() | |
# ax.set_xlabel('Probability') | |
# ax.set_xlim(0, 1) | |
# ax.set_title('Predicted Probabilities for Each Condition') | |
# plt.tight_layout() | |
# return fig | |
# # Create the Gradio interface | |
# interface = gr.Interface( | |
# fn=predict_and_plot, | |
# inputs=gr.Image(type='pil'), | |
# outputs=gr.Plot(), | |
# title="Dr. Macloomber", | |
# description="Upload an image of a retina to predict the probabilities of various eye conditions." | |
# ) | |
# # Launch the app | |
# interface.launch() | |