dhhd255 commited on
Commit
f2009fd
·
1 Parent(s): 1f3f0b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -27
app.py CHANGED
@@ -1,22 +1,3 @@
1
- import streamlit as st
2
- from tensorflow import keras
3
- import numpy as np
4
- from huggingface_hub import HfFileSystem
5
- from PIL import Image
6
-
7
- # Authenticate and download the custom model from Hugging Face Spaces
8
- fs = HfFileSystem()
9
- model_path = 'dhhd255/main_model/best_model.h5'
10
- with fs.open(model_path, 'rb') as f:
11
- model_content = f.read()
12
-
13
- # Save the model file to disk
14
- with open('best_model.h5', 'wb') as f:
15
- f.write(model_content)
16
-
17
- # Load your custom model
18
- model = keras.models.load_model('best_model.h5')
19
-
20
  # Define a function that takes an image as input and uses the model for inference
21
  def image_classifier(image):
22
  # Preprocess the input image
@@ -31,13 +12,15 @@ def image_classifier(image):
31
  # Use your custom model for inference
32
  predictions = model.predict(image)
33
 
34
- # Process the predictions and return the result
35
- result = {}
36
- for i, prediction in enumerate(predictions[0]):
37
- label = f'Label {i+1}'
38
- result[label] = prediction
 
39
 
40
- return result
 
41
 
42
  # Create a Streamlit app with an image upload input
43
  uploaded_file = st.file_uploader('Upload an image')
@@ -47,5 +30,8 @@ if uploaded_file is not None:
47
  image = np.array(image)
48
 
49
  # Use the image for inference
50
- result = image_classifier(image)
51
- st.write(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Define a function that takes an image as input and uses the model for inference
2
  def image_classifier(image):
3
  # Preprocess the input image
 
12
  # Use your custom model for inference
13
  predictions = model.predict(image)
14
 
15
+ # Get the index of the highest predicted probability
16
+ predicted_index = np.argmax(predictions[0])
17
+
18
+ # Map the index to a class label
19
+ labels = ['Healthy', 'Parkinson']
20
+ predicted_label = labels[predicted_index]
21
 
22
+ # Return the result
23
+ return predictions[0], predicted_label
24
 
25
  # Create a Streamlit app with an image upload input
26
  uploaded_file = st.file_uploader('Upload an image')
 
30
  image = np.array(image)
31
 
32
  # Use the image for inference
33
+ predictions, predicted_label = image_classifier(image)
34
+
35
+ # Display the result
36
+ st.write(f'Predictions: {predictions}')
37
+ st.write(f'Predicted label: {predicted_label}')