Thomas Chardonnens commited on
Commit
f397840
1 Parent(s): f55a150

form uint32 to int32

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -147,17 +147,21 @@ def encrypt(user_id, input_image):
147
  if input_image is None:
148
  raise gr.Error("Please choose an image first.")
149
 
 
 
 
150
  if input_image.shape != (224, 224, 3):
151
  input_image_pil = Image.fromarray(input_image)
152
  input_image_pil = input_image_pil.resize((224, 224))
153
- input_image = numpy.array(input_image_pil)
154
 
155
  # Convert to grayscale and reshape to (1, 1, 224, 224)
156
- input_image = numpy.mean(input_image, axis=2).astype(numpy.int32)
157
  input_image = input_image.reshape(1, 1, 224, 224)
158
 
159
- # Scale values to 12-bit range (0-4095)
160
- input_image = (input_image / 255.0 * 4095).astype(numpy.int32)
 
161
 
162
  # Retrieve the client API
163
  client = get_client(user_id)
 
147
  if input_image is None:
148
  raise gr.Error("Please choose an image first.")
149
 
150
+
151
+ import numpy as np
152
+ # Resize image if necessary
153
  if input_image.shape != (224, 224, 3):
154
  input_image_pil = Image.fromarray(input_image)
155
  input_image_pil = input_image_pil.resize((224, 224))
156
+ input_image = np.array(input_image_pil)
157
 
158
  # Convert to grayscale and reshape to (1, 1, 224, 224)
159
+ input_image = np.mean(input_image, axis=2).astype(np.float32)
160
  input_image = input_image.reshape(1, 1, 224, 224)
161
 
162
+ # Scale values to 12-bit range (-2048 to 2047)
163
+ input_image = (input_image / 255.0 * 4095 - 2048).astype(np.int16)
164
+ input_image = np.clip(input_image, -2048, 2047)
165
 
166
  # Retrieve the client API
167
  client = get_client(user_id)