Rekham1110 commited on
Commit
91487ce
·
verified ·
1 Parent(s): 7b31474

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -4,7 +4,7 @@ import os
4
  from dotenv import load_dotenv
5
  from simple_salesforce import Salesforce
6
  from datetime import datetime
7
- import random
8
  import shutil
9
 
10
  # Load environment variables
@@ -32,14 +32,26 @@ except Exception as e:
32
  # Valid milestones
33
  VALID_MILESTONES = ["Foundation", "Walls Erected", "Planning", "Completed"]
34
 
35
- # Mock AI prediction
36
  def mock_ai_model(image):
37
  img = image.convert("RGB")
38
  max_size = 1024
39
  img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
40
- milestone = random.choice(VALID_MILESTONES)
41
- completion_percent = random.choice([10, 30, 50, 80, 100])
42
- confidence_score = round(random.uniform(0.85, 0.95), 2)
 
 
 
 
 
 
 
 
 
 
 
 
43
  return milestone, completion_percent, confidence_score
44
 
45
  # Gradio function
 
4
  from dotenv import load_dotenv
5
  from simple_salesforce import Salesforce
6
  from datetime import datetime
7
+ import hashlib
8
  import shutil
9
 
10
  # Load environment variables
 
32
  # Valid milestones
33
  VALID_MILESTONES = ["Foundation", "Walls Erected", "Planning", "Completed"]
34
 
35
+ # Updated deterministic AI prediction based on image hash
36
  def mock_ai_model(image):
37
  img = image.convert("RGB")
38
  max_size = 1024
39
  img.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
40
+
41
+ # Convert image bytes to a hash value
42
+ img_bytes = img.tobytes()
43
+ img_hash = int(hashlib.sha256(img_bytes).hexdigest(), 16)
44
+
45
+ # Use the hash to deterministically pick milestone and percentages
46
+ milestone_index = img_hash % len(VALID_MILESTONES)
47
+ completion_choices = [10, 30, 50, 80, 100]
48
+ completion_index = (img_hash // 10) % len(completion_choices)
49
+ confidence_raw = 0.85 + ((img_hash % 1000) / 1000) * (0.95 - 0.85)
50
+ confidence_score = round(confidence_raw, 2)
51
+
52
+ milestone = VALID_MILESTONES[milestone_index]
53
+ completion_percent = completion_choices[completion_index]
54
+
55
  return milestone, completion_percent, confidence_score
56
 
57
  # Gradio function