import gradio as gr import math def calculate_cooling_time(initial_temperature_C, ambient_temperature_C, volume_coffee_ml, diameter_mug_mm, desired_temperature_C): # Constants specific_heat_water_J_per_g_C = 4.186 # in J/g°C thermal_conductivity_ceramic_W_per_m_K = 1 # in W/m·K density_water_g_per_ml = 1 # in g/ml # Convert units volume_coffee_m3 = volume_coffee_ml * 1e-6 # convert ml to m³ diameter_mug_m = diameter_mug_mm * 1e-3 # convert mm to m # Calculate the radius of the mug and the coffee radius_mug_m = diameter_mug_m / 2 radius_coffee_m = radius_mug_m # we're assuming the coffee fills the mug to the brim # Estimate the height of the coffee based on the volume height_coffee_m = volume_coffee_m3 / (math.pi * radius_coffee_m**2) # Calculate the surface area of the coffee exposed to the air surface_area_coffee_m2 = math.pi * radius_coffee_m**2 # Calculate the mass of the coffee mass_coffee_g = volume_coffee_ml * density_water_g_per_ml # convert volume to mass # Calculate the temperature difference between the coffee and the ambient temperature delta_temperature_C = initial_temperature_C - ambient_temperature_C # Estimate the cooling constant cooling_constant = (thermal_conductivity_ceramic_W_per_m_K * surface_area_coffee_m2 * delta_temperature_C) / (specific_heat_water_J_per_g_C * mass_coffee_g) # Check if the desired temperature is less than the initial temperature if desired_temperature_C >= initial_temperature_C: return "Desired temperature must be less than initial temperature" # Rearrange the temperature equation to solve for time cooling_time_s = -math.log((desired_temperature_C - ambient_temperature_C) / (initial_temperature_C - ambient_temperature_C)) / cooling_constant # Convert the cooling time from seconds to minutes cooling_time_min = cooling_time_s / 60 return cooling_time_min iface = gr.Interface( fn=calculate_cooling_time, inputs=[ gr.inputs.Number(label="Initial temperature of coffee (C)"), gr.inputs.Number(label="Ambient temperature (C)"), gr.inputs.Number(label="Volume of coffee (ml)"), gr.inputs.Number(label="Diameter of mug (mm)"), gr.inputs.Number(label="Desired temperature (C)") ], outputs=gr.outputs.Textbox(label="Estimated cooling time (minutes)"), ) iface.launch()