File size: 1,205 Bytes
0e7dc80
76f07f2
 
 
 
0e7dc80
76f07f2
 
 
0e7dc80
 
76f07f2
 
0e7dc80
76f07f2
0e7dc80
 
76f07f2
0e7dc80
 
 
76f07f2
 
0e7dc80
76f07f2
 
 
 
 
 
 
 
 
0e7dc80
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import streamlit as st
from tensorflow import keras
import numpy as np
from huggingface_hub import HfApi

# Authenticate and download the custom model from Hugging Face Spaces
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)

# Load your custom model
model = keras.models.load_model('best_model.h5')

# Define a function that takes an image as input and uses the model for inference
def image_classifier(image):
    # Preprocess the input image
    image = np.array(image)
    image = image / 255.0
    image = np.expand_dims(image, axis=0)
    
    # Use your custom model for inference
    predictions = model.predict(image)
    
    # Process the predictions and return the result
    result = {}
    for i, prediction in enumerate(predictions[0]):
        label = f'Label {i+1}'
        result[label] = prediction
    
    return result

# Create a Streamlit app with an image upload input
image = st.file_uploader('Upload an image')
if image is not None:
    result = image_classifier(image)
    st.write(result)