import gradio as gr import pandas as pd # Function to find solutions with floating-point comparison tolerance def find_solutions(i_1, i_2): m1_range = range(3, 7) # m1 between 3 and 7 m2_range = range(3, 7) # m2 between 3 and 7 valid_solutions = [] # z1 and z3 ranges under 50 z1_range = range(18, 40) z3_range = range(18, 40) tolerance = 1e-9 # Set a tolerance for floating-point comparison # Iterating over all possible combinations for m1 in m1_range: for m2 in m2_range: for z1 in z1_range: for z3 in z3_range: # Calculate left-hand side and right-hand side of the equation lhs = (i_1 + 1) * m1 * z1 rhs = (i_2 + 1) * m2 * z3 # Use a tolerance to compare floating-point numbers if abs(lhs - rhs) < tolerance: valid_solutions.append((m1, m2, z1, z3)) # Convert the list of solutions to a pandas DataFrame df = pd.DataFrame(valid_solutions, columns=['m1', 'm2', 'z1', 'z3']) return df # Create the Gradio app demo = gr.Interface( fn=find_solutions, inputs=[gr.Number(label="i_1"), gr.Number(label="i_2")], outputs=gr.DataFrame(label="Solutions"), title="iSolver | Find Valid Parameter Sets", description=""" **Find all valid solutions** to satisfy the axle spacing equation of a two-speed manual transmission system. - **Equation**: (i_1 + 1) * m_1 * z_1 = (i_2 + 1) * m_2 * z_3 - **i_i**: Conversion rates between gears - **m_i**: Modules of gears - **z_1** and **z_3**: The number of teeth on gears 1 and 3 Enter two values for **i_1** and **i_2** below: """ ) # Launch the app demo.launch(share=True)