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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import glob
|
| 4 |
+
import re
|
| 5 |
+
import base64
|
| 6 |
+
import pytz
|
| 7 |
+
from urllib.parse import quote
|
| 8 |
+
from gradio_client import Client
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
|
| 11 |
+
# 🌳🤖 AIKnowledgeTreeBuilder - Because every app needs a good costume!
|
| 12 |
+
Site_Name = 'AI Knowledge Tree Builder 📈🌿 Grow Smarter with Every Click'
|
| 13 |
+
title = "🌳✨AI Knowledge Tree Builder🛠️🤓"
|
| 14 |
+
helpURL = 'https://huggingface.co/spaces/awacke1/AIKnowledgeTreeBuilder/'
|
| 15 |
+
bugURL = 'https://huggingface.co/spaces/awacke1/AIKnowledgeTreeBuilder/'
|
| 16 |
+
icons = '🌳✨🛠️🤓'
|
| 17 |
+
st.set_page_config(
|
| 18 |
+
page_title=title,
|
| 19 |
+
page_icon=icons,
|
| 20 |
+
layout="wide",
|
| 21 |
+
initial_sidebar_state="auto",
|
| 22 |
+
menu_items={
|
| 23 |
+
'Get Help': helpURL,
|
| 24 |
+
'Report a bug': bugURL,
|
| 25 |
+
'About': title
|
| 26 |
+
}
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# Initialize session state variables
|
| 31 |
+
if 'selected_file' not in st.session_state:
|
| 32 |
+
st.session_state.selected_file = None
|
| 33 |
+
if 'view_mode' not in st.session_state:
|
| 34 |
+
st.session_state.view_mode = 'view'
|
| 35 |
+
if 'files' not in st.session_state:
|
| 36 |
+
st.session_state.files = []
|
| 37 |
+
|
| 38 |
+
# Define the markdown variables
|
| 39 |
+
Boxing_and_MMA_Commentary_and_Knowledge = """
|
| 40 |
+
# Boxing and UFC Study of 1971 - 2024 The Greatest Fights History
|
| 41 |
+
|
| 42 |
+
1. In Boxing, the most heart breaking fight in Boxing was the Boom Boom Mancini fight with Duku Kim.
|
| 43 |
+
2. After changes to Boxing made it more safe due to the heart break.
|
| 44 |
+
3. Rehydration of the brain after weight ins loss preparation for a match is life saving change.
|
| 45 |
+
4. Fighting went from 15 rounds to 12.
|
| 46 |
+
|
| 47 |
+
# UFC By Contrast..
|
| 48 |
+
1. 5 Rounds of 5 Minutes each.
|
| 49 |
+
2. Greatest UFC Fighters:
|
| 50 |
+
- Jon Jones could be the greatest of all time (GOAT) since he never lost.
|
| 51 |
+
- George St. Pierre
|
| 52 |
+
- BJ Penn
|
| 53 |
+
- Anderson Silva
|
| 54 |
+
- Mighty Mouse MMA's heart at 125 pounds
|
| 55 |
+
- Kabib retired 29 and 0
|
| 56 |
+
- Fedor Milliano
|
| 57 |
+
- Alex Pereira
|
| 58 |
+
- James Tony
|
| 59 |
+
- Randy Couture
|
| 60 |
+
3. You have to Judge them in their Championship Peak
|
| 61 |
+
4. Chris Weidman
|
| 62 |
+
5. Connor McGregor
|
| 63 |
+
6. Leg Breaking - Shin calcification and breaking baseball bats
|
| 64 |
+
|
| 65 |
+
# References:
|
| 66 |
+
1. Joe Rogan - Interview #2219
|
| 67 |
+
2. Donald J Trump
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
+
Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """
|
| 71 |
+
# Multiplayer Simulated Worlds
|
| 72 |
+
|
| 73 |
+
1. 7 Days To Die PC
|
| 74 |
+
2. ARK: Survival Evolved PC
|
| 75 |
+
3. Arma 3 PC
|
| 76 |
+
4. Atlas PC
|
| 77 |
+
5. Conan Exiles PC
|
| 78 |
+
6. Craftopia PC
|
| 79 |
+
7. DayZ PC
|
| 80 |
+
8. Eco - Global Survival PC
|
| 81 |
+
9. Empyrion - Galactic Survival PC
|
| 82 |
+
10. Factorio PC
|
| 83 |
+
11. Farming Simulator 19 PC
|
| 84 |
+
12. Crossplay
|
| 85 |
+
13. Farming Simulator 22
|
| 86 |
+
14. Last Oasis PC
|
| 87 |
+
15. Last Oasis Classic PC
|
| 88 |
+
16. Minecraft (Vanilla) PC
|
| 89 |
+
17. Crossplay
|
| 90 |
+
18. Path of Titans
|
| 91 |
+
19. Rust PC
|
| 92 |
+
20. SCP: Secret Laboratory PC
|
| 93 |
+
21. SCUM PC
|
| 94 |
+
22. Satisfactory PC
|
| 95 |
+
23. Satisfactory (Experimental) PC
|
| 96 |
+
24. Crossplay
|
| 97 |
+
25. Space Engineers
|
| 98 |
+
26. Terraria (tShock & Vanilla) PC
|
| 99 |
+
27. The Forest PC
|
| 100 |
+
28. Crossplay
|
| 101 |
+
29. Valheim
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
def get_display_name(filename):
|
| 105 |
+
"""Extract text from parentheses or return filename as is."""
|
| 106 |
+
match = re.search(r'\((.*?)\)', filename)
|
| 107 |
+
if match:
|
| 108 |
+
return match.group(1)
|
| 109 |
+
return filename
|
| 110 |
+
|
| 111 |
+
def get_time_display(filename):
|
| 112 |
+
"""Extract just the time portion from the filename."""
|
| 113 |
+
time_match = re.match(r'(\d{2}\d{2}[AP]M)', filename)
|
| 114 |
+
if time_match:
|
| 115 |
+
return time_match.group(1)
|
| 116 |
+
return filename
|
| 117 |
+
|
| 118 |
+
def sanitize_filename(text):
|
| 119 |
+
"""Create a safe filename from text while preserving spaces."""
|
| 120 |
+
# First replace unsafe characters with spaces
|
| 121 |
+
safe_text = re.sub(r'[^\w\s-]', ' ', text)
|
| 122 |
+
# Remove any multiple spaces
|
| 123 |
+
safe_text = re.sub(r'\s+', ' ', safe_text)
|
| 124 |
+
# Trim leading/trailing spaces
|
| 125 |
+
safe_text = safe_text.strip()
|
| 126 |
+
return safe_text[:50] # Limit length to 50 chars
|
| 127 |
+
|
| 128 |
+
def generate_timestamp_filename(query):
|
| 129 |
+
"""Generate filename with format: 1103AM 11032024 (Query).md"""
|
| 130 |
+
# Get current time in Central timezone
|
| 131 |
+
central = pytz.timezone('US/Central')
|
| 132 |
+
current_time = datetime.now(central)
|
| 133 |
+
|
| 134 |
+
# Format the timestamp parts
|
| 135 |
+
time_str = current_time.strftime("%I%M%p") # 1103AM format
|
| 136 |
+
date_str = current_time.strftime("%m%d%Y") # 11032024 format
|
| 137 |
+
|
| 138 |
+
# Clean up the query for filename - now preserving spaces
|
| 139 |
+
safe_query = sanitize_filename(query)
|
| 140 |
+
|
| 141 |
+
# Construct filename: "1103AM 11032024 (Input with spaces).md"
|
| 142 |
+
filename = f"{time_str} {date_str} ({safe_query}).md"
|
| 143 |
+
|
| 144 |
+
return filename
|
| 145 |
+
|
| 146 |
+
def delete_file(file_path):
|
| 147 |
+
"""Delete a file and return success status."""
|
| 148 |
+
try:
|
| 149 |
+
os.remove(file_path)
|
| 150 |
+
return True
|
| 151 |
+
except Exception as e:
|
| 152 |
+
st.error(f"Error deleting file: {e}")
|
| 153 |
+
return False
|
| 154 |
+
|
| 155 |
+
def save_ai_interaction(query, ai_result, is_rerun=False):
|
| 156 |
+
"""Save AI interaction to a markdown file with new filename format."""
|
| 157 |
+
filename = generate_timestamp_filename(query)
|
| 158 |
+
|
| 159 |
+
# Format the content differently for rerun vs normal query
|
| 160 |
+
if is_rerun:
|
| 161 |
+
content = f"""# Rerun Query
|
| 162 |
+
Original file content used for rerun:
|
| 163 |
+
|
| 164 |
+
{query}
|
| 165 |
+
|
| 166 |
+
# AI Response (Fun Version)
|
| 167 |
+
{ai_result}
|
| 168 |
+
"""
|
| 169 |
+
else:
|
| 170 |
+
content = f"""# Query: {query}
|
| 171 |
+
|
| 172 |
+
## AI Response
|
| 173 |
+
{ai_result}
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
# Save to file
|
| 177 |
+
try:
|
| 178 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
| 179 |
+
f.write(content)
|
| 180 |
+
return filename
|
| 181 |
+
except Exception as e:
|
| 182 |
+
st.error(f"Error saving file: {e}")
|
| 183 |
+
return None
|
| 184 |
+
|
| 185 |
+
def get_file_download_link(file_path):
|
| 186 |
+
"""Generate a base64 download link for a file."""
|
| 187 |
+
try:
|
| 188 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 189 |
+
content = f.read()
|
| 190 |
+
b64 = base64.b64encode(content.encode()).decode()
|
| 191 |
+
filename = os.path.basename(file_path)
|
| 192 |
+
return f'<a href="data:text/markdown;base64,{b64}" download="{filename}">{get_display_name(filename)}</a>'
|
| 193 |
+
except Exception as e:
|
| 194 |
+
st.error(f"Error creating download link: {e}")
|
| 195 |
+
return None
|
| 196 |
+
|
| 197 |
+
def extract_terms(markdown_text):
|
| 198 |
+
"""Parse markdown text and extract terms."""
|
| 199 |
+
lines = markdown_text.strip().split('\n')
|
| 200 |
+
terms = []
|
| 201 |
+
for line in lines:
|
| 202 |
+
line = re.sub(r'^[#*\->\d\.\s]+', '', line).strip()
|
| 203 |
+
if line:
|
| 204 |
+
terms.append(line)
|
| 205 |
+
return terms
|
| 206 |
+
|
| 207 |
+
def display_terms_with_links(terms):
|
| 208 |
+
"""Display terms with various search links."""
|
| 209 |
+
search_urls = {
|
| 210 |
+
"🚀🌌ArXiv": lambda k: f"/?q={quote(k)}",
|
| 211 |
+
"📖": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
| 212 |
+
"🔍": lambda k: f"https://www.google.com/search?q={quote(k)}",
|
| 213 |
+
"▶️": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
|
| 214 |
+
"🔎": lambda k: f"https://www.bing.com/search?q={quote(k)}",
|
| 215 |
+
"🐦": lambda k: f"https://twitter.com/search?q={quote(k)}",
|
| 216 |
+
}
|
| 217 |
+
for term in terms:
|
| 218 |
+
links_md = ' '.join([f"[{emoji}]({url(term)})" for emoji, url in search_urls.items()])
|
| 219 |
+
st.markdown(f"- **{term}** {links_md}", unsafe_allow_html=True)
|
| 220 |
+
|
| 221 |
+
def perform_ai_lookup(query):
|
| 222 |
+
"""Perform AI lookup using Gradio client."""
|
| 223 |
+
st.write("Performing AI Lookup...")
|
| 224 |
+
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
| 225 |
+
result1 = client.predict(
|
| 226 |
+
prompt=query,
|
| 227 |
+
llm_model_picked="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 228 |
+
stream_outputs=True,
|
| 229 |
+
api_name="/ask_llm"
|
| 230 |
+
)
|
| 231 |
+
st.markdown("### Mixtral-8x7B-Instruct-v0.1 Result")
|
| 232 |
+
st.markdown(result1)
|
| 233 |
+
result2 = client.predict(
|
| 234 |
+
prompt=query,
|
| 235 |
+
llm_model_picked="mistralai/Mistral-7B-Instruct-v0.2",
|
| 236 |
+
stream_outputs=True,
|
| 237 |
+
api_name="/ask_llm"
|
| 238 |
+
)
|
| 239 |
+
st.markdown("### Mistral-7B-Instruct-v0.2 Result")
|
| 240 |
+
st.markdown(result2)
|
| 241 |
+
combined_result = f"{result1}\n\n{result2}"
|
| 242 |
+
return combined_result
|
| 243 |
+
|
| 244 |
+
def display_file_content(file_path):
|
| 245 |
+
"""Display file content with editing capabilities."""
|
| 246 |
+
try:
|
| 247 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 248 |
+
content = f.read()
|
| 249 |
+
|
| 250 |
+
if st.session_state.view_mode == 'view':
|
| 251 |
+
# Display as markdown when viewing
|
| 252 |
+
st.markdown(content)
|
| 253 |
+
else:
|
| 254 |
+
# Edit functionality
|
| 255 |
+
edited_content = st.text_area(
|
| 256 |
+
"Edit content",
|
| 257 |
+
content,
|
| 258 |
+
height=400,
|
| 259 |
+
key=f"edit_{os.path.basename(file_path)}"
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
if st.button("Save Changes", key=f"save_{os.path.basename(file_path)}"):
|
| 263 |
+
try:
|
| 264 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 265 |
+
f.write(edited_content)
|
| 266 |
+
st.success(f"Successfully saved changes to {file_path}")
|
| 267 |
+
except Exception as e:
|
| 268 |
+
st.error(f"Error saving changes: {e}")
|
| 269 |
+
except Exception as e:
|
| 270 |
+
st.error(f"Error reading file: {e}")
|
| 271 |
+
|
| 272 |
+
def file_management_sidebar():
|
| 273 |
+
"""Redesigned sidebar with improved layout and additional functionality."""
|
| 274 |
+
st.sidebar.title("📁 File Management")
|
| 275 |
+
|
| 276 |
+
# Get list of .md files excluding README.md
|
| 277 |
+
md_files = [file for file in glob.glob("*.md") if file.lower() != 'readme.md']
|
| 278 |
+
md_files.sort()
|
| 279 |
+
st.session_state.files = md_files
|
| 280 |
+
|
| 281 |
+
if md_files:
|
| 282 |
+
st.sidebar.markdown("### Saved Files")
|
| 283 |
+
for idx, file in enumerate(md_files):
|
| 284 |
+
st.sidebar.markdown("---") # Separator between files
|
| 285 |
+
|
| 286 |
+
# Display time
|
| 287 |
+
st.sidebar.text(get_time_display(file))
|
| 288 |
+
|
| 289 |
+
# Display download link with simplified text
|
| 290 |
+
download_link = get_file_download_link(file)
|
| 291 |
+
if download_link:
|
| 292 |
+
st.sidebar.markdown(download_link, unsafe_allow_html=True)
|
| 293 |
+
|
| 294 |
+
# Action buttons in a row
|
| 295 |
+
col1, col2, col3, col4 = st.sidebar.columns(4)
|
| 296 |
+
|
| 297 |
+
with col1:
|
| 298 |
+
if st.button("📄 View", key=f"view_{idx}"):
|
| 299 |
+
st.session_state.selected_file = file
|
| 300 |
+
st.session_state.view_mode = 'view'
|
| 301 |
+
|
| 302 |
+
with col2:
|
| 303 |
+
if st.button("✏️ Edit", key=f"edit_{idx}"):
|
| 304 |
+
st.session_state.selected_file = file
|
| 305 |
+
st.session_state.view_mode = 'edit'
|
| 306 |
+
|
| 307 |
+
with col3:
|
| 308 |
+
if st.button("🔄 Rerun", key=f"rerun_{idx}"):
|
| 309 |
+
try:
|
| 310 |
+
with open(file, 'r', encoding='utf-8') as f:
|
| 311 |
+
content = f.read()
|
| 312 |
+
|
| 313 |
+
# Prepare the prompt with the prefix
|
| 314 |
+
rerun_prefix = """For the markdown below reduce the text to a humorous fun outline with emojis and markdown outline levels in outline that convey all the facts and adds wise quotes and funny statements to engage the reader:
|
| 315 |
+
|
| 316 |
+
"""
|
| 317 |
+
full_prompt = rerun_prefix + content
|
| 318 |
+
|
| 319 |
+
# Perform AI lookup and save results
|
| 320 |
+
ai_result = perform_ai_lookup(full_prompt)
|
| 321 |
+
saved_file = save_ai_interaction(content, ai_result, is_rerun=True)
|
| 322 |
+
|
| 323 |
+
if saved_file:
|
| 324 |
+
st.success(f"Created fun version in {saved_file}")
|
| 325 |
+
st.session_state.selected_file = saved_file
|
| 326 |
+
st.session_state.view_mode = 'view'
|
| 327 |
+
|
| 328 |
+
except Exception as e:
|
| 329 |
+
st.error(f"Error during rerun: {e}")
|
| 330 |
+
|
| 331 |
+
with col4:
|
| 332 |
+
if st.button("🗑️ Delete", key=f"delete_{idx}"):
|
| 333 |
+
if delete_file(file):
|
| 334 |
+
st.success(f"Deleted {file}")
|
| 335 |
+
st.rerun()
|
| 336 |
+
else:
|
| 337 |
+
st.error(f"Failed to delete {file}")
|
| 338 |
+
|
| 339 |
+
st.sidebar.markdown("---")
|
| 340 |
+
# Option to create a new markdown file
|
| 341 |
+
if st.sidebar.button("📝 Create New Note"):
|
| 342 |
+
filename = generate_timestamp_filename("New Note")
|
| 343 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
| 344 |
+
f.write("# New Markdown File\n")
|
| 345 |
+
st.sidebar.success(f"Created: {filename}")
|
| 346 |
+
st.session_state.selected_file = filename
|
| 347 |
+
st.session_state.view_mode = 'edit'
|
| 348 |
+
else:
|
| 349 |
+
st.sidebar.write("No markdown files found.")
|
| 350 |
+
if st.sidebar.button("📝 Create First Note"):
|
| 351 |
+
filename = generate_timestamp_filename("New Note")
|
| 352 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
| 353 |
+
f.write("# New Markdown File\n")
|
| 354 |
+
st.sidebar.success(f"Created: {filename}")
|
| 355 |
+
st.session_state.selected_file = filename
|
| 356 |
+
st.session_state.view_mode = 'edit'
|
| 357 |
+
|
| 358 |
+
def main():
|
| 359 |
+
st.title("AI Knowledge Tree Builder 🧠🌱 Cultivate Your AI Mindscape!")
|
| 360 |
+
|
| 361 |
+
# Process query parameters and AI lookup first
|
| 362 |
+
query_params = st.query_params
|
| 363 |
+
query = query_params.get('q', '')
|
| 364 |
+
show_initial_content = True # Flag to control initial content display
|
| 365 |
+
|
| 366 |
+
# First priority: Handle active query
|
| 367 |
+
if query:
|
| 368 |
+
show_initial_content = False # Hide initial content when showing query results
|
| 369 |
+
st.write(f"### Search query received: {query}")
|
| 370 |
+
try:
|
| 371 |
+
ai_result = perform_ai_lookup(query)
|
| 372 |
+
|
| 373 |
+
# Save the interaction
|
| 374 |
+
saved_file = save_ai_interaction(query, ai_result)
|
| 375 |
+
if saved_file:
|
| 376 |
+
st.success(f"Saved interaction to {saved_file}")
|
| 377 |
+
st.session_state.selected_file = saved_file
|
| 378 |
+
st.session_state.view_mode = 'view'
|
| 379 |
+
except Exception as e:
|
| 380 |
+
st.error(f"Error during AI lookup: {e}")
|
| 381 |
+
|
| 382 |
+
# File management sidebar
|
| 383 |
+
file_management_sidebar()
|
| 384 |
+
|
| 385 |
+
# Second priority: Display selected file content if any
|
| 386 |
+
if st.session_state.selected_file:
|
| 387 |
+
show_initial_content = False # Hide initial content when showing file content
|
| 388 |
+
if os.path.exists(st.session_state.selected_file):
|
| 389 |
+
st.markdown(f"### Current File: {st.session_state.selected_file}")
|
| 390 |
+
display_file_content(st.session_state.selected_file)
|
| 391 |
+
else:
|
| 392 |
+
st.error("Selected file no longer exists.")
|
| 393 |
+
st.session_state.selected_file = None
|
| 394 |
+
st.rerun()
|
| 395 |
+
|
| 396 |
+
# Show initial content: Either when first landing or when no interactive elements are active
|
| 397 |
+
if show_initial_content:
|
| 398 |
+
# First show the clickable terms with links
|
| 399 |
+
terms1 = extract_terms(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 400 |
+
terms2 = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 401 |
+
all_terms = terms1 + terms2
|
| 402 |
+
|
| 403 |
+
col1, col2 = st.columns(2)
|
| 404 |
+
|
| 405 |
+
with col1:
|
| 406 |
+
st.markdown("### Boxing & MMA")
|
| 407 |
+
st.markdown(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 408 |
+
st.markdown("#### Related Links")
|
| 409 |
+
display_terms_with_links(terms1)
|
| 410 |
+
|
| 411 |
+
with col2:
|
| 412 |
+
st.markdown("### Multiplayer Games")
|
| 413 |
+
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 414 |
+
st.markdown("#### Related Links")
|
| 415 |
+
display_terms_with_links(terms2)
|
| 416 |
+
|
| 417 |
+
if __name__ == "__main__":
|
| 418 |
+
main()
|