Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Function to find solutions with floating-point comparison tolerance
|
| 5 |
+
def find_solutions(i_1, i_2):
|
| 6 |
+
m1_range = range(3, 7) # m1 between 3 and 7
|
| 7 |
+
m2_range = range(3, 7) # m2 between 3 and 7
|
| 8 |
+
valid_solutions = []
|
| 9 |
+
|
| 10 |
+
# z1 and z3 ranges under 50
|
| 11 |
+
z1_range = range(18, 40)
|
| 12 |
+
z3_range = range(18, 40)
|
| 13 |
+
|
| 14 |
+
tolerance = 1e-9 # Set a tolerance for floating-point comparison
|
| 15 |
+
|
| 16 |
+
# Iterating over all possible combinations
|
| 17 |
+
for m1 in m1_range:
|
| 18 |
+
for m2 in m2_range:
|
| 19 |
+
for z1 in z1_range:
|
| 20 |
+
for z3 in z3_range:
|
| 21 |
+
# Calculate left-hand side and right-hand side of the equation
|
| 22 |
+
lhs = (i_1 + 1) * m1 * z1
|
| 23 |
+
rhs = (i_2 + 1) * m2 * z3
|
| 24 |
+
|
| 25 |
+
# Use a tolerance to compare floating-point numbers
|
| 26 |
+
if abs(lhs - rhs) < tolerance:
|
| 27 |
+
valid_solutions.append((m1, m2, z1, z3))
|
| 28 |
+
|
| 29 |
+
# Convert the list of solutions to a pandas DataFrame
|
| 30 |
+
df = pd.DataFrame(valid_solutions, columns=['m1', 'm2', 'z1', 'z3'])
|
| 31 |
+
|
| 32 |
+
return df
|
| 33 |
+
|
| 34 |
+
# Create the Gradio app
|
| 35 |
+
demo = gr.Interface(
|
| 36 |
+
fn=find_solutions,
|
| 37 |
+
inputs=[gr.Number(label="i_1"), gr.Number(label="i_2")],
|
| 38 |
+
outputs=gr.DataFrame(label="Solutions"),
|
| 39 |
+
title="iSolver | Find Valid Parameter Sets",
|
| 40 |
+
description="""
|
| 41 |
+
**Find all valid solutions** to satisfy the axle spacing equation of a two-speed manual transmission system.
|
| 42 |
+
|
| 43 |
+
- **Equation**: (i_1 + 1) * m_1 * z_1 = (i_2 + 1) * m_2 * z_3
|
| 44 |
+
- **i_i**: Conversion rates between gears
|
| 45 |
+
- **m_i**: Modules of gears
|
| 46 |
+
- **z_1** and **z_3**: The number of teeth on gears 1 and 3
|
| 47 |
+
|
| 48 |
+
Enter two values for **i_1** and **i_2** below:
|
| 49 |
+
"""
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
# Launch the app
|
| 53 |
+
demo.launch(share=True)
|