freunsev commited on
Commit
0cd975e
·
verified ·
1 Parent(s): f6a264a

Update app.py

Browse files

Update to Skin

Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -6,13 +6,13 @@ import pandas as pd
6
  import matplotlib.pyplot as plt
7
 
8
  # Load the trained model
9
- model_path = "pokemon-model_transferlearning1.keras"
10
  model = tf.keras.models.load_model(model_path)
11
 
12
  # Define the core prediction function
13
- def predict_pokemon(image):
14
  # Preprocess image
15
- image = image.resize((150, 150)) # Resize the image to 150x150
16
  image = image.convert('RGB') # Ensure image has 3 channels
17
  image = np.array(image)
18
  image = np.expand_dims(image, axis=0) # Add batch dimension
@@ -23,15 +23,15 @@ def predict_pokemon(image):
23
  # Apply softmax to get probabilities for each class
24
  probabilities = tf.nn.softmax(prediction, axis=1)
25
 
26
- # Map probabilities to Pokemon classes
27
- class_names = ['Chansey', 'Growlithe', 'Lapras']
28
- probabilities_dict = {pokemon_class: round(float(probability), 2) for pokemon_class, probability in zip(class_names, probabilities.numpy()[0])}
29
 
30
  return probabilities_dict
31
 
32
  # Streamlit interface
33
- st.title("Pokemon Classifier")
34
- st.write("Welches Pokemon hast du ausgewählt?")
35
 
36
  # Upload image
37
  uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png"])
@@ -42,24 +42,18 @@ if uploaded_image is not None:
42
  st.write("")
43
  st.write("Classifying...")
44
 
45
- predictions = predict_pokemon(image)
46
 
47
  # Display predictions as a DataFrame
48
  st.write("### Prediction Probabilities")
49
- df = pd.DataFrame(predictions.items(), columns=["Pokemon", "Probability"])
50
  st.dataframe(df)
51
 
52
  # Display predictions as a bar chart
53
  st.write("### Prediction Chart")
54
  fig, ax = plt.subplots()
55
- ax.barh(df["Pokemon"], df["Probability"], color='skyblue')
56
  ax.set_xlim(0, 1)
57
  ax.set_xlabel('Probability')
58
  ax.set_title('Prediction Probabilities')
59
- st.pyplot(fig)
60
-
61
- # Example images
62
- st.sidebar.title("Examples")
63
- example_images = ["pokemon/00000000.png","pokemon/00000001.png","pokemon/00000002.png"]
64
- for example_image in example_images:
65
- st.sidebar.image(example_image, use_column_width=True)
 
6
  import matplotlib.pyplot as plt
7
 
8
  # Load the trained model
9
+ model_path = "skin-model_transferlearning.keras"
10
  model = tf.keras.models.load_model(model_path)
11
 
12
  # Define the core prediction function
13
+ def predict_skin(image):
14
  # Preprocess image
15
+ image = image.resize((450, 450)) # Resize the image to 150x150
16
  image = image.convert('RGB') # Ensure image has 3 channels
17
  image = np.array(image)
18
  image = np.expand_dims(image, axis=0) # Add batch dimension
 
23
  # Apply softmax to get probabilities for each class
24
  probabilities = tf.nn.softmax(prediction, axis=1)
25
 
26
+ # Map probabilities to Skin condition classes
27
+ class_names = ['AKIEC', 'BCC', 'BKL', 'DF', 'MEL', 'NV', 'VASC']
28
+ probabilities_dict = {skin_class: round(float(probability), 2) for skin_class, probability in zip(class_names, probabilities.numpy()[0])}
29
 
30
  return probabilities_dict
31
 
32
  # Streamlit interface
33
+ st.title("Skin disease classifier")
34
+ st.write("Choose a picture:")
35
 
36
  # Upload image
37
  uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png"])
 
42
  st.write("")
43
  st.write("Classifying...")
44
 
45
+ predictions = predict_skin(image)
46
 
47
  # Display predictions as a DataFrame
48
  st.write("### Prediction Probabilities")
49
+ df = pd.DataFrame(predictions.items(), columns=["Condition", "Probability"])
50
  st.dataframe(df)
51
 
52
  # Display predictions as a bar chart
53
  st.write("### Prediction Chart")
54
  fig, ax = plt.subplots()
55
+ ax.barh(df["Condition"], df["Probability"], color='skyblue')
56
  ax.set_xlim(0, 1)
57
  ax.set_xlabel('Probability')
58
  ax.set_title('Prediction Probabilities')
59
+ st.pyplot(fig)