Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,20 @@
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
-
from transformers import AutoImageProcessor,
|
| 5 |
|
| 6 |
# Load model and processor
|
| 7 |
-
processor = AutoImageProcessor.from_pretrained("
|
| 8 |
-
model =
|
| 9 |
|
| 10 |
def enhance_image(image):
|
| 11 |
# Convert PIL Image to tensor
|
| 12 |
inputs = processor(images=image, return_tensors="pt").to('cpu')
|
|
|
|
| 13 |
# Forward pass
|
| 14 |
with torch.no_grad():
|
| 15 |
outputs = model(**inputs)
|
|
|
|
| 16 |
# Convert tensor back to PIL Image
|
| 17 |
enhanced_image = processor.post_process_output(outputs.pixel_values)
|
| 18 |
return enhanced_image[0]
|
|
@@ -23,7 +25,7 @@ iface = gr.Interface(
|
|
| 23 |
inputs=gr.Image(type="pil", label="Upload Dull Image"),
|
| 24 |
outputs=gr.Image(type="pil", label="Vibrant Image"),
|
| 25 |
title="Dull to Vibrant Image Enhancer",
|
| 26 |
-
description="
|
| 27 |
)
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
+
from transformers import AutoImageProcessor, AutoModelForImageProcessing
|
| 5 |
|
| 6 |
# Load model and processor
|
| 7 |
+
processor = AutoImageProcessor.from_pretrained("eugenesiow/EnhanceNet")
|
| 8 |
+
model = AutoModelForImageProcessing.from_pretrained("eugenesiow/EnhanceNet").to('cpu')
|
| 9 |
|
| 10 |
def enhance_image(image):
|
| 11 |
# Convert PIL Image to tensor
|
| 12 |
inputs = processor(images=image, return_tensors="pt").to('cpu')
|
| 13 |
+
|
| 14 |
# Forward pass
|
| 15 |
with torch.no_grad():
|
| 16 |
outputs = model(**inputs)
|
| 17 |
+
|
| 18 |
# Convert tensor back to PIL Image
|
| 19 |
enhanced_image = processor.post_process_output(outputs.pixel_values)
|
| 20 |
return enhanced_image[0]
|
|
|
|
| 25 |
inputs=gr.Image(type="pil", label="Upload Dull Image"),
|
| 26 |
outputs=gr.Image(type="pil", label="Vibrant Image"),
|
| 27 |
title="Dull to Vibrant Image Enhancer",
|
| 28 |
+
description="Enhance dull images using EnhanceNet on CPU. For faster GPU processing, duplicate this Space and enable GPU in settings."
|
| 29 |
)
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|