|
import streamlit as st |
|
from tensorflow import keras |
|
import numpy as np |
|
from huggingface_hub import HfApi |
|
|
|
|
|
hf_api = HfApi() |
|
model_url = hf_api.presigned_url('dhhd255', 'idk_test', filename='best_model.h5', token='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') |
|
r = requests.get(model_url) |
|
with open('best_model.h5', 'wb') as f: |
|
f.write(r.content) |
|
|
|
|
|
model = keras.models.load_model('best_model.h5') |
|
|
|
|
|
def image_classifier(image): |
|
|
|
image = np.array(image) |
|
image = image / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
|
|
|
|
predictions = model.predict(image) |
|
|
|
|
|
result = {} |
|
for i, prediction in enumerate(predictions[0]): |
|
label = f'Label {i+1}' |
|
result[label] = prediction |
|
|
|
return result |
|
|
|
|
|
image = st.file_uploader('Upload an image') |
|
if image is not None: |
|
result = image_classifier(image) |
|
st.write(result) |
|
|