CoolFace
Apppublic

MAThomson/CodeGraphs

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py40 linesDownload Raw Back to root
1import streamlit as st2from python_graphs import control_flow3from python_graphs import control_flow_graphviz4from python_graphs import program_utils5 6 7def plot_control_flow_graph(fn, path):8  graph = control_flow.get_control_flow_graph(fn)9  source = program_utils.getsource(fn)10  control_flow_graphviz.render(graph, include_src=source, path=path)11 12 13def sort_func(values):14    num_sort = []  # Creates an empty list to put sorted numbers into15    i = 0  # This is the index16    a = 1  # 'a' is the comparison number (this is the magic sauce)17 18    while values:  # As long as numList has numbers in it, loop the following19        if values[i] == values[-1]:20            if values[i] <= a:  # If we're at the final index AND that last number is smaller than 'a'21                num_sort.append(values.pop(i))22                i = 023        elif values[i] == values[-1]:  # Otherwise, if we reach the last position in numList24            i = 0  # reset the index back to the first position25            a += 1  # and make the comparison number a little bigger26        elif values[i] <= a:  # If we're anywhere else in the list and that number is smaller than 'a'27            num_sort.append(values.pop(i))28            i = 0  # Then reset the index back to the first position29            a += 1  # and make the comparison number a little bigger30        else:  # If none of those things happen31            i += 1  # then move on to the next number in the list32    return num_sort33 34name = "img.png"35 36plot_control_flow_graph(sort_func, name)37 38st.image(name)39 40