Prajwal-r-k commited on
Commit
3aaa3b9
·
verified ·
1 Parent(s): e837f85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import subprocess
4
  import torch
5
  from PIL import Image
 
6
 
7
  UPLOAD_FOLDER = 'uploads'
8
  OUTPUT_FOLDER = 'outputs'
@@ -18,6 +19,7 @@ def gradio_interface(image):
18
  output_path = os.path.join(OUTPUT_FOLDER, "output.png")
19
 
20
  image.save(input_path)
 
21
 
22
  try:
23
  # Ensure CUDA memory is freed before running inference
@@ -30,22 +32,33 @@ def gradio_interface(image):
30
  "--input_path", input_path,
31
  "--output_path", output_path
32
  ]
 
 
33
  result = subprocess.run(command, capture_output=True, text=True)
 
 
 
 
 
34
 
35
  if result.returncode != 0:
36
  return f"Error: {result.stderr}"
37
 
38
- # Check if output image was created
 
39
  if not os.path.exists(output_path):
40
  return "Error: Output image not generated."
41
 
42
- # Explicitly reload the image
 
 
43
  return Image.open(output_path).copy()
44
 
45
  except Exception as e:
 
46
  return f"Exception: {str(e)}"
47
 
48
- # Launch Gradio (without `share=True`)
49
  iface = gr.Interface(
50
  fn=gradio_interface,
51
  inputs=gr.Image(type="pil"),
@@ -53,4 +66,5 @@ iface = gr.Interface(
53
  title="Image Restoration with NAFNet"
54
  )
55
 
 
56
  iface.launch()
 
3
  import subprocess
4
  import torch
5
  from PIL import Image
6
+ import time
7
 
8
  UPLOAD_FOLDER = 'uploads'
9
  OUTPUT_FOLDER = 'outputs'
 
19
  output_path = os.path.join(OUTPUT_FOLDER, "output.png")
20
 
21
  image.save(input_path)
22
+ print(f"Input image saved at: {input_path}")
23
 
24
  try:
25
  # Ensure CUDA memory is freed before running inference
 
32
  "--input_path", input_path,
33
  "--output_path", output_path
34
  ]
35
+
36
+ print("Running model...")
37
  result = subprocess.run(command, capture_output=True, text=True)
38
+ print("Model execution completed.")
39
+
40
+ # Log the output
41
+ print("STDOUT:", result.stdout)
42
+ print("STDERR:", result.stderr)
43
 
44
  if result.returncode != 0:
45
  return f"Error: {result.stderr}"
46
 
47
+ # Wait for output file to be generated
48
+ time.sleep(2) # Give time for file system updates
49
  if not os.path.exists(output_path):
50
  return "Error: Output image not generated."
51
 
52
+ print(f"Output image generated: {output_path}")
53
+
54
+ # Explicitly reload the image to avoid caching issues
55
  return Image.open(output_path).copy()
56
 
57
  except Exception as e:
58
+ print(f"Exception occurred: {str(e)}")
59
  return f"Exception: {str(e)}"
60
 
61
+ # Launch Gradio
62
  iface = gr.Interface(
63
  fn=gradio_interface,
64
  inputs=gr.Image(type="pil"),
 
66
  title="Image Restoration with NAFNet"
67
  )
68
 
69
+ print("Starting Gradio interface...")
70
  iface.launch()