Update README.md
Browse files
README.md
CHANGED
@@ -3,6 +3,44 @@ library_name: transformers
|
|
3 |
tags: []
|
4 |
---
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Model Card for Model ID
|
7 |
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
|
|
3 |
tags: []
|
4 |
---
|
5 |
|
6 |
+
## Model Usage
|
7 |
+
import gradio as gr
|
8 |
+
from transformers import pipeline
|
9 |
+
from PIL import Image
|
10 |
+
import numpy as np
|
11 |
+
|
12 |
+
### Define function to perform inference
|
13 |
+
def predict_image(image):
|
14 |
+
# Initialize the pipeline outside the function if possible for efficiency
|
15 |
+
pipe = pipeline("image-classification", model="itsTomLie/Jaundice_Classifier")
|
16 |
+
|
17 |
+
# Convert NumPy array to PIL Image if necessary
|
18 |
+
if isinstance(image, np.ndarray):
|
19 |
+
image = Image.fromarray(image.astype('uint8'))
|
20 |
+
elif isinstance(image, str): # If image is a file path
|
21 |
+
image = Image.open(image)
|
22 |
+
|
23 |
+
# Perform prediction
|
24 |
+
result = pipe(image)
|
25 |
+
|
26 |
+
# Extract label and confidence
|
27 |
+
label = result[0]['label']
|
28 |
+
confidence = result[0]['score']
|
29 |
+
|
30 |
+
print(f"Prediction: {label}, Confidence: {confidence}")
|
31 |
+
|
32 |
+
return label, confidence
|
33 |
+
|
34 |
+
### Create Gradio interface
|
35 |
+
interface = gr.Interface(
|
36 |
+
fn=predict_image,
|
37 |
+
inputs=gr.Image(type="numpy", label="Upload an Image"),
|
38 |
+
outputs=[gr.Textbox(label="Prediction"), gr.Textbox(label="Confidence")]
|
39 |
+
)
|
40 |
+
|
41 |
+
interface.launch(debug=True)
|
42 |
+
|
43 |
+
|
44 |
# Model Card for Model ID
|
45 |
|
46 |
<!-- Provide a quick summary of what the model is/does. -->
|