Neurolingua commited on
Commit
5a8c585
·
verified ·
1 Parent(s): d8e7f49

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing import image
4
+ import numpy as np
5
+
6
+ # Load your trained TensorFlow face recognition model
7
+ model = tf.keras.models.load_model(r"C:\Users\tiruv\Downloads\1.h5")
8
+
9
+ # Map the predicted label to a class name
10
+ class_names = {
11
+ 0: "akilesh",
12
+ 1: "aswath",
13
+ 2: "bhuvan",
14
+ 3: "karthikeyan",
15
+ 4: "lalpradhap",
16
+ 5: "muhilan",
17
+ 6: "ragavan",
18
+ 7: "sanjay",
19
+ 8: "seenivas",
20
+ 9: "sharvesh"
21
+ }
22
+
23
+ def predict_image(img):
24
+ if img is None:
25
+ return "No image provided"
26
+
27
+ try:
28
+ # Preprocess the image
29
+ img = img.resize((224, 224)) # Ensure the size matches your training data
30
+ img_array = image.img_to_array(img)
31
+ img_array = tf.expand_dims(img_array, 0) # Create a batch of size 1
32
+
33
+ # Predict the class
34
+ predictions = model.predict(img_array)
35
+ predicted_class = np.argmax(predictions[0])
36
+
37
+ # Map prediction to class name
38
+ predicted_class_name = class_names.get(predicted_class, "Unknown class")
39
+
40
+ return predicted_class_name
41
+
42
+ except Exception as e:
43
+ return f"Error: {str(e)}"
44
+
45
+ # Create Gradio interface
46
+ gr.Interface(fn=predict_image,
47
+ inputs=gr.Image(type="pil"), # Default configuration
48
+ outputs="text",
49
+ title="Image Classifier",
50
+ description="Upload an image to classify it").launch(share=True)