Prajwal-r-k commited on
Commit
7227f0d
·
verified ·
1 Parent(s): 5e8fe36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -1,9 +1,9 @@
1
- import gradio as gr
2
  import os
 
3
  import torch
 
4
  from PIL import Image
5
  import logging
6
- from NAFNet.demo import run_model # Import the model directly instead of using subprocess
7
 
8
  # Setup logging
9
  logging.basicConfig(level=logging.INFO)
@@ -17,6 +17,19 @@ os.makedirs(OUTPUT_FOLDER, exist_ok=True)
17
  # Fix CUDA Out of Memory issue by enabling memory management
18
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def gradio_interface(image):
21
  input_path = os.path.join(UPLOAD_FOLDER, "input.png")
22
  output_path = os.path.join(OUTPUT_FOLDER, "output.png")
@@ -30,12 +43,18 @@ def gradio_interface(image):
30
 
31
  logging.info("Running model...")
32
 
33
- # Run NAFNet directly instead of subprocess
34
- run_model(
35
- opt_path="NAFNet/options/test/REDS/NAFNet-width64.yml",
36
- input_path=input_path,
37
- output_path=output_path
38
- )
 
 
 
 
 
 
39
 
40
  logging.info("Model execution completed.")
41
 
 
 
1
  import os
2
+ import subprocess
3
  import torch
4
+ import gradio as gr
5
  from PIL import Image
6
  import logging
 
7
 
8
  # Setup logging
9
  logging.basicConfig(level=logging.INFO)
 
17
  # Fix CUDA Out of Memory issue by enabling memory management
18
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
19
 
20
+ # ** Fix: Pull missing files from Git LFS **
21
+ def fix_git_lfs():
22
+ try:
23
+ logging.info("Checking and pulling missing Git LFS files...")
24
+ subprocess.run(["git", "lfs", "pull"], check=True)
25
+ logging.info("Git LFS files pulled successfully.")
26
+ except subprocess.CalledProcessError as e:
27
+ logging.error(f"Git LFS pull failed: {e}")
28
+
29
+ # Run Git LFS Fix
30
+ fix_git_lfs()
31
+
32
+ # Function to process the image
33
  def gradio_interface(image):
34
  input_path = os.path.join(UPLOAD_FOLDER, "input.png")
35
  output_path = os.path.join(OUTPUT_FOLDER, "output.png")
 
43
 
44
  logging.info("Running model...")
45
 
46
+ # Run NAFNet via subprocess (since import is failing)
47
+ command = [
48
+ "python", "NAFNet/demo.py",
49
+ "-opt", "NAFNet/options/test/REDS/NAFNet-width64.yml",
50
+ "--input_path", input_path,
51
+ "--output_path", output_path
52
+ ]
53
+ result = subprocess.run(command, capture_output=True, text=True)
54
+
55
+ if result.returncode != 0:
56
+ logging.error(f"Model error: {result.stderr}")
57
+ return f"Error: {result.stderr}"
58
 
59
  logging.info("Model execution completed.")
60