|
import os |
|
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" |
|
import gradio as gr |
|
import tensorflow as tf |
|
from tensorflow.keras.preprocessing import image |
|
import numpy as np |
|
from transformers import pipeline |
|
|
|
|
|
model = pipeline("image-classification", model="icputrd/gelderman_decomposition_classification/head/xception_070523") |
|
|
|
|
|
def classify_image(img): |
|
|
|
img = img.resize((299, 299)) |
|
img_array = image.img_to_array(img) |
|
img_array = np.expand_dims(img_array, axis=0) |
|
img_array /= 255.0 |
|
|
|
|
|
predictions = model.predict(img_array) |
|
predicted_class = np.argmax(predictions, axis=-1)[0] |
|
|
|
return str(predicted_class) |
|
|
|
|
|
demo = gr.Interface(fn=classify_image, inputs=gr.inputs.Image(type="pil"), outputs="label") |
|
demo.launch() |
|
|