import gradio as gr import time # Reynolds Number Calculation Logic def calculate_reynolds_number(velocity, diameter, density, viscosity, velocity_unit, diameter_unit, density_unit, viscosity_unit): # Unit conversions if velocity_unit == "cm/s": velocity_m = velocity / 100 elif velocity_unit == "ft/s": velocity_m = velocity * 0.3048 else: velocity_m = velocity if diameter_unit == "cm": diameter_m = diameter / 100 elif diameter_unit == "mm": diameter_m = diameter / 1000 elif diameter_unit == "ft": diameter_m = diameter * 0.3048 else: diameter_m = diameter if density_unit == "g/cm³": density_kgm3 = density * 1000 else: density_kgm3 = density if viscosity_unit == "cP": viscosity_pas = viscosity / 1000 else: viscosity_pas = viscosity try: reynolds_number = (velocity_m * diameter_m * density_kgm3) / viscosity_pas if reynolds_number < 2300: flow_type = "Laminar Flow" elif 2300 <= reynolds_number <= 4000: flow_type = "Transitional Flow" else: flow_type = "Turbulent Flow" return f"Reynolds Number: {reynolds_number:.2f} ({flow_type})" except ZeroDivisionError: return "Error: Viscosity cannot be zero." # Create a dynamic name simulation (scrolling effect) def simulate_name(): name_text = "Designed by Kamran Liaqat - 2k23-chE-05" # Adding the new text spaces = " " * 10 # Padding before the name scrolling_name = spaces + name_text + spaces result = [] for i in range(len(scrolling_name)): result.append(scrolling_name[i:] + scrolling_name[:i]) # Simulate scrolling effect by rotating the string time.sleep(0.1) # Adjust speed of scrolling return result # Centrifugal Pump Power Calculation Logic def calculate_pump_power(flow_rate, head, efficiency, density, flow_rate_unit, head_unit, density_unit): if flow_rate_unit == "L/s": flow_rate_m3s = flow_rate / 1000 elif flow_rate_unit == "gpm": flow_rate_m3s = flow_rate * 3.78541 / 60000 else: flow_rate_m3s = flow_rate / 3600 if head_unit == "ft": head_m = head * 0.3048 else: head_m = head if density_unit == "g/cm³": density_kgm3 = density * 1000 else: density_kgm3 = density try: g = 9.81 efficiency_decimal = efficiency / 100 hydraulic_power = density_kgm3 * g * flow_rate_m3s * head_m shaft_power = hydraulic_power / efficiency_decimal return f"Hydraulic Power: {hydraulic_power / 1000:.2f} kW, Shaft Power: {shaft_power / 1000:.2f} kW" except ZeroDivisionError: return "Error: Efficiency cannot be zero." # Orifice Meter Calculation Logic def calculate_orifice_meter(diameter_pipe, diameter_orifice, flow_rate, pressure_drop, diameter_unit, flow_rate_unit, pressure_unit): if diameter_unit == "cm": diameter_pipe_m = diameter_pipe / 100 diameter_orifice_m = diameter_orifice / 100 elif diameter_unit == "mm": diameter_pipe_m = diameter_pipe / 1000 diameter_orifice_m = diameter_orifice / 1000 else: diameter_pipe_m = diameter_pipe diameter_orifice_m = diameter_orifice if flow_rate_unit == "L/s": flow_rate_m3s = flow_rate / 1000 elif flow_rate_unit == "gpm": flow_rate_m3s = flow_rate * 3.78541 / 60000 else: flow_rate_m3s = flow_rate if pressure_unit == "bar": pressure_pa = pressure_drop * 1e5 elif pressure_unit == "psi": pressure_pa = pressure_drop * 6894.76 else: pressure_pa = pressure_drop try: beta = diameter_orifice_m / diameter_pipe_m discharge_coefficient = 0.61 area_orifice = 3.14159 * (diameter_orifice_m / 2) ** 2 flow_rate_calculated = ( discharge_coefficient * area_orifice * (2 * pressure_pa / 1000) ** 0.5 ) flow_rate_cgs = flow_rate_calculated * 1000000 flow_rate_imperial = flow_rate_calculated * 2118.88 return ( f"Flow Rate (SI): {flow_rate_calculated:.4f} m³/s, " f"Flow Rate (CGS): {flow_rate_cgs:.2f} cm³/s, " f"Flow Rate (Imperial): {flow_rate_imperial:.2f} gpm" ) except ZeroDivisionError: return "Error: Diameter or pressure drop cannot be zero." # Sedimentation Tank Calculation Logic def calculate_sedimentation_tank(flow_rate, length, width, depth, flow_rate_unit, length_unit, width_unit, depth_unit): if flow_rate_unit == "L/s": flow_rate_m3s = flow_rate / 1000 elif flow_rate_unit == "m³/h": flow_rate_m3s = flow_rate / 3600 else: flow_rate_m3s = flow_rate if length_unit == "cm": length_m = length / 100 elif length_unit == "mm": length_m = length / 1000 else: length_m = length if width_unit == "cm": width_m = width / 100 elif width_unit == "mm": width_m = width / 1000 else: width_m = width if depth_unit == "cm": depth_m = depth / 100 elif depth_unit == "mm": depth_m = depth / 1000 else: depth_m = depth try: tank_volume = length_m * width_m * depth_m detention_time = tank_volume / flow_rate_m3s return f"Tank Volume: {tank_volume:.2f} m³, Detention Time: {detention_time:.2f} seconds" except ZeroDivisionError: return "Error: Flow rate cannot be zero." # Bernoulli's Equation Calculation Logic def calculate_bernoulli(p1, p2, v1, v2, h1, h2, p_unit, v_unit, h_unit): # Unit conversions if p_unit == "Pa": p1_pa = p1 p2_pa = p2 elif p_unit == "bar": p1_pa = p1 * 1e5 p2_pa = p2 * 1e5 elif p_unit == "psi": p1_pa = p1 * 6894.76 p2_pa = p2 * 6894.76 else: p1_pa = p1 p2_pa = p2 if v_unit == "m/s": v1_mps = v1 v2_mps = v2 elif v_unit == "cm/s": v1_mps = v1 / 100 v2_mps = v2 / 100 elif v_unit == "ft/s": v1_mps = v1 * 0.3048 v2_mps = v2 * 0.3048 else: v1_mps = v1 v2_mps = v2 if h_unit == "m": h1_m = h1 h2_m = h2 elif h_unit == "cm": h1_m = h1 / 100 h2_m = h2 / 100 elif h_unit == "ft": h1_m = h1 * 0.3048 h2_m = h2 * 0.3048 else: h1_m = h1 h2_m = h2 try: # Bernoulli's equation: p1 + 0.5 * rho * v1^2 + rho * g * h1 = p2 + 0.5 * rho * v2^2 + rho * g * h2 g = 9.81 # gravity in m/s² rho = 1000 # density of water in kg/m³ # Calculate the change in pressure based on Bernoulli's equation delta_p = (0.5 * rho * (v2_mps**2 - v1_mps**2)) + (rho * g * (h2_m - h1_m)) + (p1_pa - p2_pa) return f"Pressure Difference (ΔP): {delta_p:.2f} Pa" except ZeroDivisionError: return "Error: Zero value input encountered." # Gradio Interface with gr.Blocks() as demo: # Custom CSS for background color gr.HTML(""" """) # Name Template Section with Scrolling Effect gr.Markdown("# Designed by Kamran Liaqat - 2k23-chE-05") # Start a simulation for scrolling name name_simulation = simulate_name() scrolling_text = gr.Textbox(value="", label="Scrolling Name", interactive=False) def update_scrolling_text(): for name in name_simulation: scrolling_text.update(value=name) time.sleep(0.1) # Supervised by Hidaytullah Mahar in Small Font beneath scrolling name gr.Markdown("