Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,6 +45,14 @@ def generate_mindmap_step(notes_chunk, current_mindmap=None):
|
|
| 45 |
New lecture notes chunk:
|
| 46 |
{notes_chunk}
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
Return only the JSON structure of the entire updated mindmap, without any additional text or explanation.
|
| 49 |
Ensure the JSON is valid and complete.
|
| 50 |
"""
|
|
@@ -72,18 +80,21 @@ def generate_mindmap_step(notes_chunk, current_mindmap=None):
|
|
| 72 |
return None
|
| 73 |
|
| 74 |
def display_mindmap(data, indent=0):
|
| 75 |
-
if isinstance(data, str):
|
| 76 |
-
try:
|
| 77 |
-
data = json.loads(data)
|
| 78 |
-
except json.JSONDecodeError:
|
| 79 |
-
st.error("Failed to parse the mindmap data. Please try again.")
|
| 80 |
-
return
|
| 81 |
-
|
| 82 |
if isinstance(data, dict):
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
if 'children' in data and isinstance(data['children'], list):
|
| 85 |
-
for child in data['children']:
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
elif isinstance(data, list):
|
| 88 |
for item in data:
|
| 89 |
display_mindmap(item, indent)
|
|
@@ -126,6 +137,16 @@ if st.button("Clear and Restart"):
|
|
| 126 |
if st.session_state.current_mindmap:
|
| 127 |
st.subheader("Current Mindmap")
|
| 128 |
display_mindmap(st.session_state.current_mindmap)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
st.write("""
|
| 131 |
To use this app:
|
|
@@ -134,6 +155,7 @@ To use this app:
|
|
| 134 |
3. The mindmap will be generated in chunks, and you can see the progress.
|
| 135 |
4. If the process is interrupted, you can continue from where it left off.
|
| 136 |
5. Use the "Clear and Restart" button to start over with new notes.
|
|
|
|
| 137 |
|
| 138 |
This app uses Google's Gemini AI to structure your notes into a hierarchical mindmap format.
|
| 139 |
It processes the notes in multiple steps to handle large inputs and complex structures.
|
|
|
|
| 45 |
New lecture notes chunk:
|
| 46 |
{notes_chunk}
|
| 47 |
|
| 48 |
+
Follow these guidelines to create a well-structured mindmap:
|
| 49 |
+
1. Create clear, concise node names.
|
| 50 |
+
2. Maintain a logical hierarchy with main topics and subtopics.
|
| 51 |
+
3. Ensure consistent depth across similar levels of information.
|
| 52 |
+
4. Group related concepts together.
|
| 53 |
+
5. Use parallel structure in naming sibling nodes.
|
| 54 |
+
6. Limit the number of main topics to 3-7 for better organization.
|
| 55 |
+
|
| 56 |
Return only the JSON structure of the entire updated mindmap, without any additional text or explanation.
|
| 57 |
Ensure the JSON is valid and complete.
|
| 58 |
"""
|
|
|
|
| 80 |
return None
|
| 81 |
|
| 82 |
def display_mindmap(data, indent=0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if isinstance(data, dict):
|
| 84 |
+
if indent == 0:
|
| 85 |
+
st.markdown(f"# {data['name']}")
|
| 86 |
+
else:
|
| 87 |
+
prefix = " " * (indent - 1) + ("└─ " if indent > 0 else "")
|
| 88 |
+
st.markdown(f"{prefix}**{data['name']}**")
|
| 89 |
+
|
| 90 |
if 'children' in data and isinstance(data['children'], list):
|
| 91 |
+
for i, child in enumerate(data['children']):
|
| 92 |
+
if i == len(data['children']) - 1:
|
| 93 |
+
display_mindmap(child, indent + 1)
|
| 94 |
+
else:
|
| 95 |
+
display_mindmap(child, indent + 1)
|
| 96 |
+
if indent == 0:
|
| 97 |
+
st.markdown("---") # Add a horizontal line between main topics
|
| 98 |
elif isinstance(data, list):
|
| 99 |
for item in data:
|
| 100 |
display_mindmap(item, indent)
|
|
|
|
| 137 |
if st.session_state.current_mindmap:
|
| 138 |
st.subheader("Current Mindmap")
|
| 139 |
display_mindmap(st.session_state.current_mindmap)
|
| 140 |
+
|
| 141 |
+
# Add an option to download the mindmap as JSON
|
| 142 |
+
if st.button("Download Mindmap as JSON"):
|
| 143 |
+
json_string = json.dumps(st.session_state.current_mindmap, indent=2)
|
| 144 |
+
st.download_button(
|
| 145 |
+
label="Click here to download",
|
| 146 |
+
file_name="mindmap.json",
|
| 147 |
+
mime="application/json",
|
| 148 |
+
data=json_string
|
| 149 |
+
)
|
| 150 |
|
| 151 |
st.write("""
|
| 152 |
To use this app:
|
|
|
|
| 155 |
3. The mindmap will be generated in chunks, and you can see the progress.
|
| 156 |
4. If the process is interrupted, you can continue from where it left off.
|
| 157 |
5. Use the "Clear and Restart" button to start over with new notes.
|
| 158 |
+
6. You can download the generated mindmap as a JSON file for future reference.
|
| 159 |
|
| 160 |
This app uses Google's Gemini AI to structure your notes into a hierarchical mindmap format.
|
| 161 |
It processes the notes in multiple steps to handle large inputs and complex structures.
|