Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ genai.configure(api_key=GOOGLE_API_KEY)
|
|
| 13 |
# Use Gemini 1.5 Flash model
|
| 14 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 15 |
|
| 16 |
-
def
|
| 17 |
if image is None:
|
| 18 |
return "Error: Please upload or capture a banknote image."
|
| 19 |
|
|
@@ -21,40 +21,29 @@ def authenticate_banknote(image):
|
|
| 21 |
image = image.resize((224, 224))
|
| 22 |
|
| 23 |
prompt = """
|
| 24 |
-
You are an image analysis assistant tasked with
|
| 25 |
-
Analyze the image for
|
| 26 |
-
Identify the denomination based on visual elements like currency symbols, colors, numbers, or portraits.
|
| 27 |
Return the response in this format:
|
| 28 |
|
| 29 |
-
Prediction: [Authentic / Fake]
|
| 30 |
-
Reason for Authenticity: [Brief explanation]
|
| 31 |
Denomination: [Value, e.g., $10, €20]
|
| 32 |
-
Reason
|
| 33 |
|
| 34 |
Examples:
|
| 35 |
-
Image Description: A banknote with a
|
| 36 |
-
Prediction: Authentic
|
| 37 |
-
Reason for Authenticity: The presence of a color-shifting security thread, clear watermark, legible microtext, color-shifting ink, crisp paper, sharp printing, and holographic features are strong indicators of an authentic banknote.
|
| 38 |
Denomination: $100
|
| 39 |
-
Reason
|
| 40 |
|
| 41 |
-
Image Description: A banknote with
|
| 42 |
-
Prediction: Fake
|
| 43 |
-
Reason for Authenticity: The absence of a security thread, blurry watermark, illegible microtext, lack of color-shifting ink, rough paper, and blurry printing suggest a counterfeit banknote.
|
| 44 |
Denomination: €50
|
| 45 |
-
Reason
|
| 46 |
|
| 47 |
-
Image Description: A banknote with a
|
| 48 |
-
Prediction: Authentic
|
| 49 |
-
Reason for Authenticity: The presence of a security thread, clear watermark, legible microtext, and color-shifting ink are consistent with an authentic banknote.
|
| 50 |
Denomination: £20
|
| 51 |
-
Reason
|
| 52 |
|
| 53 |
Analyze the provided image.
|
| 54 |
-
Prediction:
|
| 55 |
-
Reason for Authenticity:
|
| 56 |
Denomination:
|
| 57 |
-
Reason
|
| 58 |
"""
|
| 59 |
|
| 60 |
try:
|
|
@@ -65,11 +54,11 @@ def authenticate_banknote(image):
|
|
| 65 |
|
| 66 |
# Define Gradio interface
|
| 67 |
iface = gr.Interface(
|
| 68 |
-
fn=
|
| 69 |
inputs=gr.Image(type="pil", label="Upload or capture a banknote image", sources=["upload", "webcam"]),
|
| 70 |
-
outputs=gr.Textbox(label="Banknote
|
| 71 |
-
title="Banknote
|
| 72 |
-
description="Upload or capture a banknote image to
|
| 73 |
)
|
| 74 |
|
| 75 |
# Launch the interface
|
|
|
|
| 13 |
# Use Gemini 1.5 Flash model
|
| 14 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 15 |
|
| 16 |
+
def identify_banknote_denomination(image):
|
| 17 |
if image is None:
|
| 18 |
return "Error: Please upload or capture a banknote image."
|
| 19 |
|
|
|
|
| 21 |
image = image.resize((224, 224))
|
| 22 |
|
| 23 |
prompt = """
|
| 24 |
+
You are an image analysis assistant tasked with identifying the denomination (worth) of a banknote from an image.
|
| 25 |
+
Analyze the image for visual elements like currency symbols, colors, numbers, or portraits to determine the denomination.
|
|
|
|
| 26 |
Return the response in this format:
|
| 27 |
|
|
|
|
|
|
|
| 28 |
Denomination: [Value, e.g., $10, €20]
|
| 29 |
+
Reason: [Brief explanation]
|
| 30 |
|
| 31 |
Examples:
|
| 32 |
+
Image Description: A banknote with a green color scheme, a portrait of a historical figure, and "$100" printed prominently.
|
|
|
|
|
|
|
| 33 |
Denomination: $100
|
| 34 |
+
Reason: The green color scheme, portrait, and "$100" text are consistent with a U.S. $100 note.
|
| 35 |
|
| 36 |
+
Image Description: A banknote with a blue color scheme, a bridge image, and "€50" printed.
|
|
|
|
|
|
|
| 37 |
Denomination: €50
|
| 38 |
+
Reason: The blue color scheme, bridge image, and "€50" text indicate a Euro €50 note.
|
| 39 |
|
| 40 |
+
Image Description: A banknote with a purple color scheme, a specific building, and "£20" printed.
|
|
|
|
|
|
|
| 41 |
Denomination: £20
|
| 42 |
+
Reason: The purple color scheme, building image, and "£20" text are consistent with a British £20 note.
|
| 43 |
|
| 44 |
Analyze the provided image.
|
|
|
|
|
|
|
| 45 |
Denomination:
|
| 46 |
+
Reason:
|
| 47 |
"""
|
| 48 |
|
| 49 |
try:
|
|
|
|
| 54 |
|
| 55 |
# Define Gradio interface
|
| 56 |
iface = gr.Interface(
|
| 57 |
+
fn=identify_banknote_denomination,
|
| 58 |
inputs=gr.Image(type="pil", label="Upload or capture a banknote image", sources=["upload", "webcam"]),
|
| 59 |
+
outputs=gr.Textbox(label="Banknote Denomination Result"),
|
| 60 |
+
title="Banknote Denomination Predictor",
|
| 61 |
+
description="Upload or capture a banknote image to identify its denomination using the Gemini API. Set your GOOGLE_API_KEY in the Hugging Face Space settings. Note: This is for demonstration purposes only and not for real-world banking use."
|
| 62 |
)
|
| 63 |
|
| 64 |
# Launch the interface
|