ddecosmo commited on
Commit
9e97c11
·
verified ·
1 Parent(s): 3a19e1f

Upload 2 files

Browse files
Files changed (2) hide show
  1. requirements.txt +5 -0
  2. threadcheckerv1_gui.py +65 -0
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ huggingface_hub
3
+ tensorflow
4
+ numpy
5
+ pillow
threadcheckerv1_gui.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """threadcheckerv1_gui.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/145qYaJaBGKmbGoSNYSsFlMASN1PUKEgF
8
+ """
9
+
10
+ import numpy as np
11
+ from PIL import Image
12
+ import gradio as gr
13
+ import huggingface_hub
14
+ from tensorflow.keras.models import load_model
15
+
16
+ # Load model from Hugging Face Hub
17
+ repo_id = "ddecosmo/thread_checker_v1"
18
+ model_filename = "thread_checker_model.keras"
19
+ model_path = huggingface_hub.hf_hub_download(repo_id=repo_id, filename=model_filename)
20
+ model = load_model(model_path)
21
+
22
+ # Example images (replace with actual files in your repo if desired)
23
+ example_images = [
24
+ "/content/sample_data/threaded_example.jpg",
25
+ "/content/sample_data/unthreaded_example.jpg"
26
+ ]
27
+
28
+ def predict_image(image):
29
+ """
30
+ Predicts the class of an image using the loaded Keras model and returns
31
+ confidence scores for all classes and the final determination.
32
+ """
33
+ img_width, img_height = model.input_shape[1:3]
34
+ image = image.resize((img_width, img_height))
35
+ image = np.array(image).astype("float32") / 255.0
36
+ image = np.expand_dims(image, axis=0)
37
+
38
+ predictions = model.predict(image)
39
+ confidence_scores = predictions[0]
40
+
41
+ predicted_class_index = np.argmax(confidence_scores)
42
+ class_labels = ["0.125", "0.25", "0.375"]
43
+ final_determination = class_labels[predicted_class_index]
44
+
45
+ return (
46
+ float(confidence_scores[0]),
47
+ float(confidence_scores[1]),
48
+ float(confidence_scores[2]),
49
+ final_determination,
50
+ )
51
+
52
+ iface = gr.Interface(
53
+ fn=predict_image,
54
+ inputs=gr.Image(type="pil"),
55
+ outputs=[
56
+ gr.Number(label="Confidence (0.125)"),
57
+ gr.Number(label="Confidence (0.25)"),
58
+ gr.Number(label="Confidence (0.375)"),
59
+ gr.Textbox(label="Final Determination"),
60
+ ],
61
+ examples=example_images,
62
+ )
63
+
64
+ if __name__ == "__main__":
65
+ iface.launch()