Update README.md
Browse files
README.md
CHANGED
@@ -4,26 +4,22 @@ 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):
|
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 |
|
@@ -31,7 +27,6 @@ def predict_image(image):
|
|
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"),
|
@@ -39,7 +34,7 @@ interface = gr.Interface(
|
|
39 |
)
|
40 |
|
41 |
interface.launch(debug=True)
|
42 |
-
|
43 |
|
44 |
# Model Card for Model ID
|
45 |
|
|
|
4 |
---
|
5 |
|
6 |
## Model Usage
|
7 |
+
```
|
8 |
import gradio as gr
|
9 |
from transformers import pipeline
|
10 |
from PIL import Image
|
11 |
import numpy as np
|
12 |
|
|
|
13 |
def predict_image(image):
|
|
|
14 |
pipe = pipeline("image-classification", model="itsTomLie/Jaundice_Classifier")
|
15 |
|
|
|
16 |
if isinstance(image, np.ndarray):
|
17 |
image = Image.fromarray(image.astype('uint8'))
|
18 |
+
elif isinstance(image, str):
|
19 |
image = Image.open(image)
|
20 |
|
|
|
21 |
result = pipe(image)
|
22 |
|
|
|
23 |
label = result[0]['label']
|
24 |
confidence = result[0]['score']
|
25 |
|
|
|
27 |
|
28 |
return label, confidence
|
29 |
|
|
|
30 |
interface = gr.Interface(
|
31 |
fn=predict_image,
|
32 |
inputs=gr.Image(type="numpy", label="Upload an Image"),
|
|
|
34 |
)
|
35 |
|
36 |
interface.launch(debug=True)
|
37 |
+
```
|
38 |
|
39 |
# Model Card for Model ID
|
40 |
|