dkescape commited on
Commit
10b1715
·
verified ·
1 Parent(s): d5b7c66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -42
app.py CHANGED
@@ -32,57 +32,32 @@ def enhance_image(img_path, brightness=1.0, contrast=1.0):
32
  image.save(enhanced_path)
33
  return enhanced_path
34
 
35
- def process_single_image(img_path, brightness, contrast):
36
  colorized_path = colorize_image(img_path)
37
  enhanced_path = enhance_image(colorized_path, brightness, contrast)
38
  return [img_path, enhanced_path], enhanced_path
39
 
40
- def process_batch_images(img_paths, brightness, contrast):
41
- results = []
42
- for img_path in img_paths:
43
- colorized_path = colorize_image(img_path)
44
- enhanced_path = enhance_image(colorized_path, brightness, contrast)
45
- results.append((enhanced_path, os.path.basename(img_path)))
46
- return results
47
-
48
  title = "🌈 Color Restorization Model"
49
- description = "Upload black & white photos to restore them in color using a deep learning model."
50
 
51
  with gr.Blocks(title=title) as demo:
52
  gr.Markdown(f"## {title}")
53
  gr.Markdown(description)
54
 
55
- with gr.Tab("Single Image"):
56
- with gr.Row():
57
- with gr.Column():
58
- input_image = gr.Image(type="filepath", label="Upload B&W Image")
59
- brightness_slider = gr.Slider(0.5, 2.0, value=1.0, label="Brightness")
60
- contrast_slider = gr.Slider(0.5, 2.0, value=1.0, label="Contrast")
61
- submit_btn = gr.Button("Colorize")
62
- with gr.Column():
63
- comparison = gr.Gallery(label="Original vs Colorized").style(grid=[2], height="auto")
64
- download_btn = gr.File(label="Download Colorized Image")
65
-
66
- submit_btn.click(
67
- fn=process_single_image,
68
- inputs=[input_image, brightness_slider, contrast_slider],
69
- outputs=[comparison, download_btn]
70
- )
71
-
72
- with gr.Tab("Batch Processing"):
73
- with gr.Row():
74
- with gr.Column():
75
- batch_input = gr.File(file_types=["image"], file_count="multiple", label="Upload Multiple B&W Images")
76
- batch_brightness_slider = gr.Slider(0.5, 2.0, value=1.0, label="Brightness")
77
- batch_contrast_slider = gr.Slider(0.5, 2.0, value=1.0, label="Contrast")
78
- batch_submit_btn = gr.Button("Colorize Batch")
79
- with gr.Column():
80
- batch_output = gr.Gallery(label="Batch Colorized Images").style(grid=[3], height="auto")
81
-
82
- batch_submit_btn.click(
83
- fn=process_batch_images,
84
- inputs=[batch_input, batch_brightness_slider, batch_contrast_slider],
85
- outputs=batch_output
86
- )
87
 
88
  demo.launch(enable_queue=True)
 
32
  image.save(enhanced_path)
33
  return enhanced_path
34
 
35
+ def process_image(img_path, brightness, contrast):
36
  colorized_path = colorize_image(img_path)
37
  enhanced_path = enhance_image(colorized_path, brightness, contrast)
38
  return [img_path, enhanced_path], enhanced_path
39
 
 
 
 
 
 
 
 
 
40
  title = "🌈 Color Restorization Model"
41
+ description = "Upload a black & white photo to restore it in color using a deep learning model."
42
 
43
  with gr.Blocks(title=title) as demo:
44
  gr.Markdown(f"## {title}")
45
  gr.Markdown(description)
46
 
47
+ with gr.Row():
48
+ with gr.Column():
49
+ input_image = gr.Image(type="filepath", label="Upload B&W Image")
50
+ brightness_slider = gr.Slider(0.5, 2.0, value=1.0, label="Brightness")
51
+ contrast_slider = gr.Slider(0.5, 2.0, value=1.0, label="Contrast")
52
+ submit_btn = gr.Button("Colorize")
53
+ with gr.Column():
54
+ comparison = gr.Gallery(label="Original vs Colorized").style(grid=[2], height="auto")
55
+ download_btn = gr.File(label="Download Colorized Image")
56
+
57
+ submit_btn.click(
58
+ fn=process_image,
59
+ inputs=[input_image, brightness_slider, contrast_slider],
60
+ outputs=[comparison, download_btn]
61
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  demo.launch(enable_queue=True)