Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Commit 
							
							·
						
						e5cc9a3
	
1
								Parent(s):
							
							3aa0d47
								
Create classifier.py
Browse files- classifier.py +18 -0
 
    	
        classifier.py
    ADDED
    
    | 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 1 | 
         
            +
            import tensorflow as tf
         
     | 
| 2 | 
         
            +
            from tf.keras.models import load_model
         
     | 
| 3 | 
         
            +
            model = load_model('myModel.hdf5')
         
     | 
| 4 | 
         
            +
             
     | 
| 5 | 
         
            +
            import gradio as gr
         
     | 
| 6 | 
         
            +
             
     | 
| 7 | 
         
            +
            def classify(inp):
         
     | 
| 8 | 
         
            +
              img_array = tf.keras.utils.img_to_array(img)
         
     | 
| 9 | 
         
            +
              img_array = tf.expand_dims(img_array, 0) # Create a batch
         
     | 
| 10 | 
         
            +
              predictions = model.predict(img_array)
         
     | 
| 11 | 
         
            +
              score = tf.nn.softmax(predictions[0])
         
     | 
| 12 | 
         
            +
              confidences = {class_names[i]: float(score[i]) for i in range(5)}
         
     | 
| 13 | 
         
            +
              return confidences
         
     | 
| 14 | 
         
            +
             
     | 
| 15 | 
         
            +
            gr.Interface(fn=classify, 
         
     | 
| 16 | 
         
            +
                         inputs=gr.Image(shape=(180, 180)),
         
     | 
| 17 | 
         
            +
                         outputs=gr.Label(num_top_classes=5)).launch(debug=True)
         
     | 
| 18 | 
         
            +
                        
         
     |