Doodhwala commited on
Commit
822d8ca
·
verified ·
1 Parent(s): e42a0fe

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load your pre-trained model (e.g., TensorFlow Keras model)
7
+ # Replace "currency_model.h5" with the actual path to your model
8
+ model = tf.keras.models.load_model("counterfeitmodel.h5")
9
+
10
+ # Define the prediction function
11
+ def detect_currency(image):
12
+ """
13
+ Function to detect if the input image is of a real or fake currency note.
14
+ :param image: Uploaded image (.jpg)
15
+ :return: String indicating 'Real' or 'Fake'
16
+ """
17
+ # Resize the image to match the input size expected by the model
18
+ input_size = (200, 200) # Replace with your model's expected input size
19
+ image = image.resize(input_size)
20
+
21
+ # Convert the image to a NumPy array
22
+ image_array = np.array(image) / 255.0 # Normalize pixel values to [0, 1]
23
+
24
+ # Add batch dimension
25
+ image_array = np.expand_dims(image_array, axis=0)
26
+
27
+ # Perform prediction
28
+ prediction = model.predict(image_array)
29
+
30
+ # Assume the model outputs a probability for 'Real' (1) and 'Fake' (0)
31
+ is_real = prediction[0][0] > 0.5
32
+ return "Real Currency Note" if is_real else "Fake Currency Note"
33
+ css ="""
34
+ #currency-image {
35
+ border: 2px solid #00BFFF;
36
+ border-radius: 10px;
37
+ padding: 10px;
38
+ }
39
+
40
+ #prediction-output {
41
+ font-size: 20px;
42
+ font-weight: bold;
43
+ color: #2c3e50;
44
+ margin-top: 20px;
45
+ text-align: center;
46
+ background-color: #ecf0f1;
47
+ border: 2px solid #00BFFF;
48
+ border-radius: 10px;
49
+ padding: 10px;
50
+ }
51
+ """
52
+ # Create the Gradio interface
53
+ interface = gr.Interface(
54
+ fn=detect_currency, # The function to run
55
+ inputs=gr.Image(type="pil", label="Upload Currency Image (.jpg)"), # Input type
56
+ outputs="text", # Output type
57
+ title="Currency Note Detector",
58
+ description="Upload a .jpg image of a currency note to check if it's real or fake.",
59
+ theme=gr.themes.Base(), # Hugging Face theme for a professional look
60
+ live=True,
61
+ css=css,
62
+ )
63
+
64
+ # Add the custom CSS to the interface
65
+
66
+ # Launch the app
67
+ interface.launch(share=True)