Spaces:
No application file
No application file
Upload 2 files
Browse files
NO_BREAK_RELIABILITY_app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import math
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# Function to calculate binomial coefficient
|
8 |
+
def binom(n, k):
|
9 |
+
return math.factorial(n) // (math.factorial(k) * math.factorial(n - k))
|
10 |
+
|
11 |
+
# Function to calculate total reliability with redundancy
|
12 |
+
def total_reliability_with_redundancy(N, X, MTBF, t):
|
13 |
+
R = np.exp(-t / MTBF) # Reliability of a single component at time t
|
14 |
+
R_total = 0
|
15 |
+
for k in range(X + 1): # Summing up to account for up to X failures
|
16 |
+
R_total += binom(N + X, k) * (R ** (N + X - k)) * ((1 - R) ** k)
|
17 |
+
return R_total * 100 # Convert to percentage
|
18 |
+
|
19 |
+
# Function to generate the plot
|
20 |
+
def plot_reliability(N, X, MTBF, time_hours):
|
21 |
+
t = np.linspace(0, 20000, 500) # Time range (0 to 20,000 hours)
|
22 |
+
R_total = [total_reliability_with_redundancy(N, X, MTBF, ti) for ti in t]
|
23 |
+
|
24 |
+
# Calculate reliability at the selected time in percentage
|
25 |
+
R_at_time = total_reliability_with_redundancy(N, X, MTBF, time_hours)
|
26 |
+
|
27 |
+
# Create the plot
|
28 |
+
plt.figure(figsize=(10, 6))
|
29 |
+
plt.plot(t, R_total, label=f'Total reliability (N={N}, X={X}, MTBF={MTBF} hours)')
|
30 |
+
|
31 |
+
# Draw vertical line at the selected time point
|
32 |
+
plt.axvline(x=time_hours, color='red', linestyle='--', label=f'Time = {time_hours} hours')
|
33 |
+
|
34 |
+
# Draw horizontal line at the corresponding reliability
|
35 |
+
plt.axhline(y=R_at_time, color='blue', linestyle='--', label=f'Reliability = {R_at_time:.2f}%')
|
36 |
+
|
37 |
+
# Plot the intersection point (green)
|
38 |
+
plt.scatter(time_hours, R_at_time, color='green', s=100, zorder=5, label='Intersection Point')
|
39 |
+
|
40 |
+
# Set labels and title
|
41 |
+
plt.xlabel('Time (hours)')
|
42 |
+
plt.ylabel('Reliability (%)')
|
43 |
+
plt.title('Total System Reliability with Redundancy')
|
44 |
+
plt.ylim(0, 100)
|
45 |
+
plt.grid(True)
|
46 |
+
plt.legend()
|
47 |
+
|
48 |
+
# Save the plot to a file and return it
|
49 |
+
plt.savefig("reliability_plot.png")
|
50 |
+
plt.close()
|
51 |
+
return "reliability_plot.png"
|
52 |
+
|
53 |
+
# Define Gradio interface
|
54 |
+
def gradio_interface(N, X, MTBF, time_hours):
|
55 |
+
return plot_reliability(N, X, MTBF, time_hours)
|
56 |
+
|
57 |
+
# Create the Gradio interface
|
58 |
+
gradio_app = gr.Interface(
|
59 |
+
fn=gradio_interface,
|
60 |
+
inputs=[
|
61 |
+
gr.Slider(1, 10, value=3, label="N (components)"),
|
62 |
+
gr.Slider(0, 5, value=1, label="X (redundancy)"),
|
63 |
+
gr.Slider(1000, 50000, step=1000, value=10000, label="MTBF (hours)"),
|
64 |
+
gr.Slider(0, 20000, step=100, value=5000, label="Hours")
|
65 |
+
],
|
66 |
+
outputs=gr.Image(label="Reliability Plot"),
|
67 |
+
title="System Reliability with Redundancy",
|
68 |
+
description="Adjust the sliders to change the parameters of the system and view the corresponding reliability curve."
|
69 |
+
)
|
70 |
+
|
71 |
+
# Launch the app
|
72 |
+
gradio_app.launch()
|
NO_BREAK_RELIABILITY_requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
matplotlib
|