JustinGerm commited on
Commit
ca3fa03
1 Parent(s): 6e019e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import math
3
 
4
- def calculate_coffee_temp(cooling_time_min, initial_temperature_C, ambient_temperature_C, volume_coffee_ml, diameter_mug_mm):
5
  # Constants
6
  specific_heat_water_J_per_g_C = 4.186 # in J/g°C
7
  thermal_conductivity_ceramic_W_per_m_K = 1 # in W/m·K
@@ -30,24 +30,28 @@ def calculate_coffee_temp(cooling_time_min, initial_temperature_C, ambient_tempe
30
  # Estimate the cooling constant
31
  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)
32
 
33
- # Convert time to seconds
34
- cooling_time_s = cooling_time_min * 60 # convert minutes to seconds
 
35
 
36
- # Calculate the temperature of the coffee after the specified time
37
- temperature_C = ambient_temperature_C + (initial_temperature_C - ambient_temperature_C) * math.exp(-cooling_constant * cooling_time_s)
38
 
39
- return temperature_C
 
 
 
40
 
41
  iface = gr.Interface(
42
- fn=calculate_coffee_temp,
43
  inputs=[
44
- gr.inputs.Number(label="Cooling time (minutes)"),
45
  gr.inputs.Number(label="Initial temperature of coffee (C)"),
46
  gr.inputs.Number(label="Ambient temperature (C)"),
47
  gr.inputs.Number(label="Volume of coffee (ml)"),
48
- gr.inputs.Number(label="Diameter of mug (mm)")
 
49
  ],
50
- outputs=gr.outputs.Textbox(label="Estimated coffee temperature (C)"),
51
  )
52
 
53
  iface.launch()
 
1
  import gradio as gr
2
  import math
3
 
4
+ def calculate_cooling_time(initial_temperature_C, ambient_temperature_C, volume_coffee_ml, diameter_mug_mm, desired_temperature_C):
5
  # Constants
6
  specific_heat_water_J_per_g_C = 4.186 # in J/g°C
7
  thermal_conductivity_ceramic_W_per_m_K = 1 # in W/m·K
 
30
  # Estimate the cooling constant
31
  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)
32
 
33
+ # Check if the desired temperature is less than the initial temperature
34
+ if desired_temperature_C >= initial_temperature_C:
35
+ return "Desired temperature must be less than initial temperature"
36
 
37
+ # Rearrange the temperature equation to solve for time
38
+ cooling_time_s = -math.log((desired_temperature_C - ambient_temperature_C) / (initial_temperature_C - ambient_temperature_C)) / cooling_constant
39
 
40
+ # Convert the cooling time from seconds to minutes
41
+ cooling_time_min = cooling_time_s / 60
42
+
43
+ return cooling_time_min
44
 
45
  iface = gr.Interface(
46
+ fn=calculate_cooling_time,
47
  inputs=[
 
48
  gr.inputs.Number(label="Initial temperature of coffee (C)"),
49
  gr.inputs.Number(label="Ambient temperature (C)"),
50
  gr.inputs.Number(label="Volume of coffee (ml)"),
51
+ gr.inputs.Number(label="Diameter of mug (mm)"),
52
+ gr.inputs.Number(label="Desired temperature (C)")
53
  ],
54
+ outputs=gr.outputs.Textbox(label="Estimated cooling time (minutes)"),
55
  )
56
 
57
  iface.launch()