Update app.py
Browse files
app.py
CHANGED
@@ -1,77 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import random
|
3 |
-
from colors import *
|
4 |
-
from bubbleSort import bubble_sort
|
5 |
-
from selectionSort import selection_sort
|
6 |
-
from insertionSort import insertion_sort
|
7 |
-
from quickSort import quick_sort
|
8 |
-
|
9 |
-
|
10 |
-
# Create a Streamlit app
|
11 |
-
st.set_page_config(page_title='Sorting Algorithms Visualization', layout='wide')
|
12 |
-
st.title("Sorting Algorithms Visualization")
|
13 |
-
|
14 |
-
# Initialize the data list
|
15 |
-
data = []
|
16 |
-
|
17 |
-
def draw_data(data, color_array):
|
18 |
-
"""
|
19 |
-
Function to display the data on Streamlit.
|
20 |
-
"""
|
21 |
-
st.write("### Sorting Visualization")
|
22 |
-
|
23 |
-
# Convert data to a chart-friendly format
|
24 |
-
chart_data = {"Index": list(range(len(data))), "Value": data}
|
25 |
-
|
26 |
-
# Display the bar chart using Streamlit's built-in plotting
|
27 |
-
chart = st.bar_chart(chart_data, use_container_width=True)
|
28 |
-
|
29 |
-
def generate():
|
30 |
-
"""
|
31 |
-
Function to generate random data.
|
32 |
-
"""
|
33 |
-
global data
|
34 |
-
data = [random.randint(1, 150) for _ in range(100)]
|
35 |
-
draw_data(data, [BLUE for _ in range(len(data))])
|
36 |
-
|
37 |
-
def set_speed():
|
38 |
-
"""
|
39 |
-
Function to set speed based on the selected speed level.
|
40 |
-
"""
|
41 |
-
speed = st.selectbox('Select Sorting Speed', ['Fast', 'Medium', 'Slow'])
|
42 |
-
if speed == 'Slow':
|
43 |
-
return 0.3
|
44 |
-
elif speed == 'Medium':
|
45 |
-
return 0.1
|
46 |
-
else:
|
47 |
-
return 0.001
|
48 |
-
|
49 |
-
def sort():
|
50 |
-
"""
|
51 |
-
Function to sort the data based on selected algorithm.
|
52 |
-
"""
|
53 |
-
global data
|
54 |
-
time_tick = set_speed()
|
55 |
-
algorithm = st.selectbox('Select Sorting Algorithm', [
|
56 |
-
'Bubble Sort',
|
57 |
-
'Selection Sort',
|
58 |
-
'Insertion Sort',
|
59 |
-
'Quick Sort'
|
60 |
-
])
|
61 |
-
|
62 |
-
if algorithm == 'Bubble Sort':
|
63 |
-
bubble_sort(data, draw_data, time_tick)
|
64 |
-
elif algorithm == 'Selection Sort':
|
65 |
-
selection_sort(data, draw_data, time_tick)
|
66 |
-
elif algorithm == 'Insertion Sort':
|
67 |
-
insertion_sort(data, draw_data, time_tick)
|
68 |
-
elif algorithm == 'Quick Sort':
|
69 |
-
quick_sort(data, 0, len(data)-1, draw_data, time_tick)
|
70 |
-
|
71 |
-
# Streamlit buttons and actions
|
72 |
-
if st.button('Generate Array'):
|
73 |
-
generate()
|
74 |
-
|
75 |
-
if st.button('Sort'):
|
76 |
-
sort()
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|