DHEIVER commited on
Commit
415b382
·
1 Parent(s): 026e1a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,13 +1,21 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load the breast cancer image classification model
5
- model = pipeline("image-classification", model="OverDriveLee/Breast_Cancer")
 
6
 
7
- # Define the prediction function
8
  def classify_image(image):
9
- results = model(image)
10
- return {"prediction": results[0]["label"], "confidence": results[0]["score"]}
 
 
 
 
 
 
 
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(