muhammadhamza-stack
commited on
Commit
·
5405e62
1
Parent(s):
21a7c00
update the port number
Browse files- Dockerfile +1 -1
- app.py +1 -172
Dockerfile
CHANGED
|
@@ -20,6 +20,6 @@ RUN pip install --upgrade pip \
|
|
| 20 |
|
| 21 |
COPY . .
|
| 22 |
|
| 23 |
-
EXPOSE
|
| 24 |
|
| 25 |
CMD ["python", "app.py"]
|
|
|
|
| 20 |
|
| 21 |
COPY . .
|
| 22 |
|
| 23 |
+
EXPOSE 7860
|
| 24 |
|
| 25 |
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -1,174 +1,3 @@
|
|
| 1 |
-
# import gradio as gr
|
| 2 |
-
# import torch
|
| 3 |
-
# import os
|
| 4 |
-
# import tempfile
|
| 5 |
-
# import shutil
|
| 6 |
-
# from PIL import Image
|
| 7 |
-
# import numpy as np
|
| 8 |
-
# from pathlib import Path
|
| 9 |
-
# import sys
|
| 10 |
-
# import copy
|
| 11 |
-
|
| 12 |
-
# # --- Import logic from your project ---
|
| 13 |
-
# from options.test_options import TestOptions
|
| 14 |
-
# from data import create_dataset
|
| 15 |
-
# from models import create_model
|
| 16 |
-
# try:
|
| 17 |
-
# from best_ldr import compute_metrics_for_images, score_records
|
| 18 |
-
# except ImportError:
|
| 19 |
-
# raise ImportError("Could not import from best_ldr.py. Make sure the file is in the same directory as app.py.")
|
| 20 |
-
|
| 21 |
-
# print("--- Initializing LDR-to-HDR Model (this may take a moment) ---")
|
| 22 |
-
|
| 23 |
-
# # --- Global Setup: Load the CycleGAN model once when the app starts ---
|
| 24 |
-
|
| 25 |
-
# # We need to satisfy the parser's requirement for a dataroot at startup
|
| 26 |
-
# if '--dataroot' not in sys.argv:
|
| 27 |
-
# sys.argv.extend(['--dataroot', './dummy_dataroot_for_init'])
|
| 28 |
-
|
| 29 |
-
# # Load the base options
|
| 30 |
-
# opt = TestOptions().parse()
|
| 31 |
-
|
| 32 |
-
# # Manually override settings for our model
|
| 33 |
-
# opt.name = 'ldr2hdr_cyclegan_728'
|
| 34 |
-
# opt.model = 'test'
|
| 35 |
-
# opt.netG = 'resnet_9blocks'
|
| 36 |
-
# opt.norm = 'instance'
|
| 37 |
-
# opt.no_dropout = True
|
| 38 |
-
# opt.checkpoints_dir = './checkpoints'
|
| 39 |
-
# opt.gpu_ids = [0] if torch.cuda.is_available() else []
|
| 40 |
-
# opt.device = torch.device('cuda:{}'.format(opt.gpu_ids[0])) if opt.gpu_ids else torch.device('cpu')
|
| 41 |
-
|
| 42 |
-
# # Create the model using these options
|
| 43 |
-
# model = create_model(opt)
|
| 44 |
-
# model.setup(opt)
|
| 45 |
-
# model.eval()
|
| 46 |
-
|
| 47 |
-
# print("--- Model Loaded Successfully ---")
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# # --- Helper Function for Inference ---
|
| 51 |
-
|
| 52 |
-
# def run_inference(model, image_path, process_options):
|
| 53 |
-
# """
|
| 54 |
-
# A reusable function to run the model with specific preprocessing options.
|
| 55 |
-
# """
|
| 56 |
-
# # Deep copy the base options to avoid modifying the global state
|
| 57 |
-
# local_opt = copy.deepcopy(opt)
|
| 58 |
-
|
| 59 |
-
# # Apply the specific settings for this run
|
| 60 |
-
# for key, value in process_options.items():
|
| 61 |
-
# setattr(local_opt, key, value)
|
| 62 |
-
|
| 63 |
-
# with tempfile.TemporaryDirectory() as temp_dir:
|
| 64 |
-
# shutil.copy(image_path, temp_dir)
|
| 65 |
-
# local_opt.dataroot = temp_dir
|
| 66 |
-
# local_opt.num_test = 1
|
| 67 |
-
# dataset = create_dataset(local_opt)
|
| 68 |
-
|
| 69 |
-
# for i, data in enumerate(dataset):
|
| 70 |
-
# model.set_input(data)
|
| 71 |
-
# model.test()
|
| 72 |
-
# visuals = model.get_current_visuals()
|
| 73 |
-
|
| 74 |
-
# for label, image_tensor in visuals.items():
|
| 75 |
-
# if label == 'fake':
|
| 76 |
-
# image_numpy = (np.transpose(image_tensor.cpu().float().numpy()[0], (1, 2, 0)) + 1) / 2.0 * 255.0
|
| 77 |
-
# return Image.fromarray(image_numpy.astype(np.uint8))
|
| 78 |
-
|
| 79 |
-
# # --- The Main Gradio Processing Function ---
|
| 80 |
-
|
| 81 |
-
# def process_images_and_display(list_of_temp_files):
|
| 82 |
-
# """
|
| 83 |
-
# The main workflow: select best LDR, then run two inference modes.
|
| 84 |
-
# """
|
| 85 |
-
# if not list_of_temp_files:
|
| 86 |
-
# raise gr.Error("Please upload your bracketed LDR images.")
|
| 87 |
-
# if len(list_of_temp_files) < 2:
|
| 88 |
-
# gr.Warning("For best results, upload at least 2 bracketed LDR images.")
|
| 89 |
-
|
| 90 |
-
# uploaded_filepaths = [Path(f.name) for f in list_of_temp_files]
|
| 91 |
-
|
| 92 |
-
# try:
|
| 93 |
-
# # --- Step 1: Select the Best LDR ---
|
| 94 |
-
# print(f"Analyzing {len(uploaded_filepaths)} uploaded images...")
|
| 95 |
-
# weights = {"clipped": 0.35, "coverage": 0.25, "exposure": 0.15, "sharpness": 0.15, "noise": 0.10}
|
| 96 |
-
# records = compute_metrics_for_images(uploaded_filepaths, resize_max=1024)
|
| 97 |
-
# scored_records = score_records(records, weights)
|
| 98 |
-
# if not scored_records:
|
| 99 |
-
# raise gr.Error("Could not read or score any of the uploaded images.")
|
| 100 |
-
|
| 101 |
-
# best_ldr_record = scored_records[0]
|
| 102 |
-
# best_ldr_path = best_ldr_record['path']
|
| 103 |
-
# print(f"Best LDR selected: {os.path.basename(best_ldr_path)} (Score: {best_ldr_record['score']:.4f})")
|
| 104 |
-
# chosen_ldr_image = Image.open(best_ldr_path).convert("RGB")
|
| 105 |
-
|
| 106 |
-
# # --- Step 2: Run Inference in Both Modes ---
|
| 107 |
-
|
| 108 |
-
# # Mode A: High-Quality Crop (at model's native resolution)
|
| 109 |
-
# print("Running Mode A: High-Quality Crop...")
|
| 110 |
-
# crop_options = {
|
| 111 |
-
# 'preprocess': 'resize_and_crop',
|
| 112 |
-
# 'load_size': 728,
|
| 113 |
-
# 'crop_size': 728
|
| 114 |
-
# }
|
| 115 |
-
# hdr_cropped = run_inference(model, best_ldr_path, crop_options)
|
| 116 |
-
# print("Mode A successful.")
|
| 117 |
-
|
| 118 |
-
# # Mode B: Full Image (at a higher resolution)
|
| 119 |
-
# print("Running Mode B: Full Image (High-Res Scaled)...")
|
| 120 |
-
# scale_options = {
|
| 121 |
-
# 'preprocess': 'scale_width',
|
| 122 |
-
# 'load_size': 1024, # <-- THIS IS THE CHANGE FOR HIGHER RESOLUTION
|
| 123 |
-
# 'crop_size': 728 # This value is ignored by scale_width but needs to be present
|
| 124 |
-
# }
|
| 125 |
-
# hdr_scaled = run_inference(model, best_ldr_path, scale_options)
|
| 126 |
-
# print("Mode B successful.")
|
| 127 |
-
|
| 128 |
-
# # Return all the images to update the UI
|
| 129 |
-
# return uploaded_filepaths, chosen_ldr_image, hdr_cropped, hdr_scaled
|
| 130 |
-
|
| 131 |
-
# except Exception as e:
|
| 132 |
-
# print(f"An error occurred: {e}")
|
| 133 |
-
# raise gr.Error(f"An error occurred during processing: {e}")
|
| 134 |
-
|
| 135 |
-
# # --- Create and Launch the Gradio Interface ---
|
| 136 |
-
|
| 137 |
-
# with gr.Blocks(theme=gr.themes.Monochrome(), css="footer {display: none !important}") as demo:
|
| 138 |
-
# gr.Markdown("# LDR Bracketing to HDR Converter")
|
| 139 |
-
# gr.Markdown("Upload a set of bracketed LDR images. The app will automatically select the best one and convert it to HDR using two different methods for comparison.")
|
| 140 |
-
|
| 141 |
-
# with gr.Row():
|
| 142 |
-
# with gr.Column(scale=1, min_width=300):
|
| 143 |
-
# input_files = gr.Files(
|
| 144 |
-
# label="Upload Bracketed LDR Images",
|
| 145 |
-
# file_types=["image"]
|
| 146 |
-
# )
|
| 147 |
-
# process_button = gr.Button("Process Images", variant="primary")
|
| 148 |
-
|
| 149 |
-
# with gr.Accordion("See Your Uploads", open=False):
|
| 150 |
-
# input_gallery = gr.Gallery(label="Uploaded LDR Bracket", show_label=False, columns=3, height="auto")
|
| 151 |
-
|
| 152 |
-
# with gr.Column(scale=2):
|
| 153 |
-
# gr.Markdown("## Results")
|
| 154 |
-
# with gr.Row():
|
| 155 |
-
# chosen_ldr_display = gr.Image(label="Best LDR Chosen by Algorithm", type="pil", interactive=False)
|
| 156 |
-
# with gr.Row():
|
| 157 |
-
# output_cropped = gr.Image(label="Result 1: High-Quality Crop (728x728)", type="pil", interactive=False)
|
| 158 |
-
# output_scaled = gr.Image(label="Result 2: Full Image (Scaled to 1024px Width)", type="pil", interactive=False)
|
| 159 |
-
|
| 160 |
-
# process_button.click(
|
| 161 |
-
# fn=process_images_and_display,
|
| 162 |
-
# inputs=input_files,
|
| 163 |
-
# outputs=[input_gallery, chosen_ldr_display, output_cropped, output_scaled]
|
| 164 |
-
# )
|
| 165 |
-
|
| 166 |
-
# print("--- Launching Gradio App ---")
|
| 167 |
-
# demo.launch(share=True)
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
import gradio as gr
|
| 173 |
import torch
|
| 174 |
import os
|
|
@@ -438,5 +267,5 @@ with gr.Blocks(theme=gr.themes.Soft(), css="footer {display: none !important}")
|
|
| 438 |
print("--- Launching Gradio App ---")
|
| 439 |
demo.launch(
|
| 440 |
server_name="0.0.0.0",
|
| 441 |
-
server_port=
|
| 442 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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