Spaces:
Runtime error
Runtime error
add cache and spinner
Browse files
app.py
CHANGED
|
@@ -21,10 +21,31 @@ path = st.text_input(
|
|
| 21 |
value="py_code_analyzer",
|
| 22 |
)
|
| 23 |
|
| 24 |
-
python_files = CodeFetcher().get_python_files(owner, repo, path)
|
| 25 |
-
imports_graph = CodeImportsAnalyzer(python_files).analyze().generate_imports_graph()
|
| 26 |
-
ImportsGraphVisualizer().visualize(imports_graph)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
value="py_code_analyzer",
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
@st.cache
|
| 26 |
+
def get_python_files(owner, repo, path):
|
| 27 |
+
return CodeFetcher().get_python_files(owner, repo, path)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@st.cache
|
| 31 |
+
def generate_imports_graph(python_files):
|
| 32 |
+
return CodeImportsAnalyzer(python_files).analyze().generate_imports_graph()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@st.cache
|
| 36 |
+
def generate_graph_visualization_file(imports_graph):
|
| 37 |
+
ImportsGraphVisualizer().visualize(imports_graph)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@st.cache
|
| 41 |
+
def read_graph_visualization_file():
|
| 42 |
+
imports_graph_html = open("nx.html", "r", encoding="utf-8")
|
| 43 |
+
return imports_graph_html.read()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
if owner and repo:
|
| 47 |
+
with st.spinner("Please wait..."):
|
| 48 |
+
generate_graph_visualization_file(
|
| 49 |
+
generate_imports_graph(get_python_files(owner, repo, path))
|
| 50 |
+
)
|
| 51 |
+
components.html(read_graph_visualization_file(), height=800)
|