lyimo commited on
Commit
3015beb
·
verified ·
1 Parent(s): 5307f35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -41,14 +41,25 @@ def save_hash(hash_code, description=""):
41
  # Function to check image authenticity
42
  def check_authenticity(image):
43
  hash_code = hash_image(image)
44
- with open("hash.txt", "r") as file:
45
- hashes = file.readlines()
46
- for line in hashes:
47
- saved_hash, description = line.strip().split(': ', 1)
48
- if saved_hash == hash_code:
49
- return f"Image is authentic. Description: {description}"
 
 
 
 
 
 
 
 
 
 
50
  return "Image is new or modified."
51
 
 
52
  def process_image(image, description):
53
  hash_code1 = hash_image(image)
54
  qr_img = generate_qr_code(hash_code1)
 
41
  # Function to check image authenticity
42
  def check_authenticity(image):
43
  hash_code = hash_image(image)
44
+ try:
45
+ with open("hash.txt", "r") as file:
46
+ hashes = file.readlines()
47
+ for line in hashes:
48
+ parts = line.strip().split(': ', 1)
49
+ if len(parts) == 2:
50
+ saved_hash, description = parts
51
+ if saved_hash == hash_code:
52
+ return f"Image is authentic. Description: {description}"
53
+ else:
54
+ # Handle the case where there is no ':' or description
55
+ saved_hash = parts[0]
56
+ if saved_hash == hash_code:
57
+ return "Image is authentic, but no description provided."
58
+ except FileNotFoundError:
59
+ return "Hash file not found. Please process an image first."
60
  return "Image is new or modified."
61
 
62
+
63
  def process_image(image, description):
64
  hash_code1 = hash_image(image)
65
  qr_img = generate_qr_code(hash_code1)