Ariamehr commited on
Commit
4a0dd7b
·
verified ·
1 Parent(s): 761ccc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -10,25 +10,29 @@ model = torch.jit.load(model_path, map_location=torch.device('cpu'))
10
  # Define the prediction function
11
  def predict(image):
12
  try:
13
- print("Predict function called") # Check if the function is being called
 
 
 
 
14
 
15
  # Preprocess image
16
  image = image.convert("RGB")
17
  input_tensor = torch.from_numpy(np.array(image)).permute(2, 0, 1).unsqueeze(0).float() / 255.0
18
 
19
- print("Image preprocessed") # Check if preprocessing is successful
20
 
21
  # Run the model
22
  with torch.no_grad():
23
  output = model(input_tensor)
24
 
25
- print("Model executed") # Check if model execution is successful
26
 
27
  # Postprocess the output
28
  output_image = output.squeeze().permute(1, 2, 0).numpy()
29
  output_image = (output_image * 255).astype(np.uint8)
30
 
31
- print("Output generated") # Check if postprocessing is successful
32
  return Image.fromarray(output_image)
33
 
34
  except Exception as e:
@@ -36,6 +40,7 @@ def predict(image):
36
  return None
37
 
38
 
 
39
  # Gradio Interface
40
  iface = gr.Interface(
41
  fn=predict,
 
10
  # Define the prediction function
11
  def predict(image):
12
  try:
13
+ print("Predict function called")
14
+
15
+ # تغییر اندازه تصویر به اندازه‌ای که مدل نیاز دارد
16
+ target_size = (3072, 3072) # یا هر اندازه‌ای که مدل نیاز دارد
17
+ image = image.resize(target_size)
18
 
19
  # Preprocess image
20
  image = image.convert("RGB")
21
  input_tensor = torch.from_numpy(np.array(image)).permute(2, 0, 1).unsqueeze(0).float() / 255.0
22
 
23
+ print("Image preprocessed")
24
 
25
  # Run the model
26
  with torch.no_grad():
27
  output = model(input_tensor)
28
 
29
+ print("Model executed")
30
 
31
  # Postprocess the output
32
  output_image = output.squeeze().permute(1, 2, 0).numpy()
33
  output_image = (output_image * 255).astype(np.uint8)
34
 
35
+ print("Output generated")
36
  return Image.fromarray(output_image)
37
 
38
  except Exception as e:
 
40
  return None
41
 
42
 
43
+
44
  # Gradio Interface
45
  iface = gr.Interface(
46
  fn=predict,