Spaces:
Runtime error
Runtime error
Update app.py
Browse files10 unmodified lines1112131415163 unmodified lines202122232425262728293031323334353653 unmodified lines9091929394959697989910010110210322 unmodified lines12612712812913013113213313413513613713813914014114214314414514614723 unmodified lines17117217317417517617748 unmodified lines22622722822923023123223323410 unmodified linesimport multiprocessingfrom modules.enhance import enhancement_pipeline, detect_brightnessfrom modules.metrics import calculate_execution_metrics, get_image_infofrom modules.dataset_loader import get_lol_dataset_samples, load_lol_pair3 unmodified linesmodel = load_model("lowlight_enhancer.keras")# ---------------------------------------------------------# AI ENHANCEMENT (FIXED - SHARPENING ADDED)# ---------------------------------------------------------def model_enhance(img):img_resized = cv2.resize(img, (128,128)) / 255.0pred = model.predict(np.expand_dims(img_resized, axis=0), verbose=0)[0]pred = (pred * 255).astype(np.uint8)pred = cv2.resize(pred, (img.shape[1], img.shape[0]))# 🔥 FIX BLUR (Sharpening)kernel = np.array([[0,-1,0],[-1,5,-1],[0,-1,0]])pred = cv2.filter2D(pred, -1, kernel)return pred53 unmodified lines)# ---------------------------------------------------------# CORE FUNCTION (FIXED PARALLEL ISSUE)# ---------------------------------------------------------def run_image_enhancement(input_img):config = {"gamma": gamma_val,"clahe_limit": clahe_clip,"denoise_h": denoise_h}# AI MODEL22 unmodified lines"speedup": 1.0}# PARALLEL (SAFE VERSION WITHOUT ARTIFACTS)else:# 🔥 FIX: avoid chunk-based processing (no lines)start = time.time()result = enhancement_pipeline(input_img, config)par_time = time.time() - start# simulate parallel speedup (for academic demonstration)simulated_seq = par_time * 1.5return {"result": result,"sequential_time": simulated_seq,"parallel_time": par_time,"speedup": simulated_seq / par_time}# ---------------------------------------------------------# MAIN APP23 unmodified linesif st.button("Run Enhancement"):with st.spinner("Processing..."):metrics = run_image_enhancement(img_np)col1, col2 = st.columns(2)48 unmodified linescol2.image(high, caption="Ground Truth")enhanced = enhancement_pipeline(low, {"gamma": gamma_val,"clahe_limit": clahe_clip,"denoise_h": denoise_h})col3.image(enhanced, caption="Enhanced")10 unmodified lines111213141516173 unmodified lines21222324252627282930313233343536373839404153 unmodified lines959697989910010110210310410510610710810911011111211322 unmodified lines13613713813914014114214314414514614714814923 unmodified lines17317417517617717848 unmodified lines22722822923023123223323423523623723823910 unmodified linesimport multiprocessingfrom modules.enhance import enhancement_pipeline, detect_brightnessfrom modules.parallel import parallel_enhancementfrom modules.metrics import calculate_execution_metrics, get_image_infofrom modules.dataset_loader import get_lol_dataset_samples, load_lol_pair3 unmodified linesmodel = load_model("lowlight_enhancer.keras")# ---------------------------------------------------------# AI ENHANCEMENT (FIXED PROPERLY)# ---------------------------------------------------------def model_enhance(img):h, w = img.shape[:2]img_resized = cv2.resize(img, (128,128))img_resized = img_resized / 255.0pred = model.predict(np.expand_dims(img_resized, axis=0), verbose=0)[0]pred = (pred * 255).astype(np.uint8)pred = cv2.resize(pred, (w, h))# 🔥 Better than sharpening (reduces blur properly)pred = cv2.detailEnhance(pred, sigma_s=10, sigma_r=0.15)return pred53 unmodified lines)# ---------------------------------------------------------# CORE FUNCTION (FIXED CONFIG + PARALLEL)# ---------------------------------------------------------def run_image_enhancement(input_img):config = {"gamma_enable": True,"gamma": gamma_val,"clahe_enable": True,"clahe_clip": clahe_clip,"denoise_enable": True,"denoise_h": denoise_h,"sharpen_enable": True,"cores": parallel_cores}# AI MODEL22 unmodified lines"speedup": 1.0}# PARALLELelse:return calculate_execution_metrics(enhancement_pipeline,parallel_enhancement,input_img,config)# ---------------------------------------------------------# MAIN APP23 unmodified linesif st.button("Run Enhancement"):with st.spinner("Processing..."):metrics = run_image_enhancement(img_np)col1, col2 = st.columns(2)48 unmodified linescol2.image(high, caption="Ground Truth")enhanced = enhancement_pipeline(low, {"gamma_enable": True,"gamma": gamma_val,"clahe_enable": True,"clahe_clip": clahe_clip,"denoise_enable": True,"denoise_h": denoise_h,"sharpen_enable": True})col3.image(enhanced, caption="Enhanced")
app.py+32-27