Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
# Load the
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
# Define the prediction function
|
| 8 |
def classify_image(image):
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Define the Gradio interface
|
| 13 |
iface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
| 3 |
|
| 4 |
+
# Load the feature extractor and model directly
|
| 5 |
+
extractor = AutoFeatureExtractor.from_pretrained("ALM-AHME/beit-large-patch16-224-finetuned-BreastCancer-Classification-BreakHis-AH-60-20-20")
|
| 6 |
+
model = AutoModelForImageClassification.from_pretrained("ALM-AHME/beit-large-patch16-224-finetuned-BreastCancer-Classification-BreakHis-AH-60-20-20")
|
| 7 |
|
| 8 |
+
# Define the prediction function using the loaded model
|
| 9 |
def classify_image(image):
|
| 10 |
+
# Preprocess the image and get the features
|
| 11 |
+
inputs = extractor(images=image, return_tensors="pt")
|
| 12 |
+
# Make the prediction using the model
|
| 13 |
+
outputs = model(**inputs)
|
| 14 |
+
logits = outputs.logits
|
| 15 |
+
# Get the predicted label and confidence
|
| 16 |
+
predicted_label = logits.argmax(dim=1).item()
|
| 17 |
+
confidence = logits.softmax(dim=1).max().item()
|
| 18 |
+
return {"prediction": predicted_label, "confidence": confidence}
|
| 19 |
|
| 20 |
# Define the Gradio interface
|
| 21 |
iface = gr.Interface(
|