Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
import glob | |
import re | |
import base64 | |
import pytz | |
from urllib.parse import quote | |
from gradio_client import Client | |
from datetime import datetime | |
# ๐ณ๐ค AIKnowledgeTreeBuilder - Because every app needs a good costume! | |
Site_Name = 'AI Knowledge Tree Builder ๐๐ฟ Grow Smarter with Every Click' | |
title = "๐ณโจAI Knowledge Tree Builder๐ ๏ธ๐ค" | |
helpURL = 'https://huggingface.co/spaces/awacke1/AIKnowledgeTreeBuilder/' | |
bugURL = 'https://huggingface.co/spaces/awacke1/AIKnowledgeTreeBuilder/' | |
icons = '๐ณโจ๐ ๏ธ๐ค' | |
st.set_page_config( | |
page_title=title, | |
page_icon=icons, | |
layout="wide", | |
initial_sidebar_state="auto", | |
menu_items={ | |
'Get Help': helpURL, | |
'Report a bug': bugURL, | |
'About': title | |
} | |
) | |
# Initialize session state variables | |
if 'selected_file' not in st.session_state: | |
st.session_state.selected_file = None | |
if 'view_mode' not in st.session_state: | |
st.session_state.view_mode = 'view' | |
if 'files' not in st.session_state: | |
st.session_state.files = [] | |
DarioAmodeiKnowledge=""" | |
๐ข Major AI Companies & Competition | |
๐ต OpenAI - Key competitor in AI development | |
๐ฆ Google - Major player in AI research and development | |
โก xAI - Emerging competitor in AI space | |
๐ค Meta - Significant presence in AI development | |
๐ฏ Anthropic's Approach & Philosophy | |
๐ "Race to the Top" theory of change | |
๐ Focus on setting positive industry examples | |
๐ค Goal to encourage other companies to "be the good guy" | |
๐ Strategy of continuous innovation in responsible AI | |
๐ Mechanistic Interpretability | |
๐จโ๐ฌ Co-founded by Chris Olah at Anthropic | |
๐งฉ Focuses on understanding AI model internals | |
๐ Initially had no commercial application | |
๐ Built and shared results publicly | |
๐ Industry Impact | |
๐ซ Other companies adopted interpretability practices | |
๐ Created positive competitive pressure | |
๐ฑ Companies motivated to appear responsible | |
๐ Led to industry-wide ripple effects | |
๐งช Technical Discoveries | |
๐งฎ Found surprisingly clean internal structures | |
๐ Discovered induction heads | |
๐ Developed sparse auto-encoder techniques | |
๐ Identified concept-specific directions in networks | |
๐ฅ Team Building Philosophy | |
๐ซ "Talent density beats talent mass" principle | |
๐ฏ Focus on highly motivated, mission-aligned individuals | |
๐ Quality of team members affects organizational culture | |
๐โโ๏ธ Growth approach: | |
๐ Rapid growth (300 to 800 in 7-8 months) | |
๐ Deliberate slowdown at ~1000 employees | |
โ๏ธ Emphasis on careful scaling | |
๐งช Ideal AI Researcher Qualities | |
๐ง Open-mindedness as primary quality | |
๐ฌ Scientific mindset for experimentation | |
๐ Ability to look at problems with fresh eyes | |
๐ Willingness to explore unconventional approaches | |
๐ Capacity for rapid experimentation | |
๐ Background examples: | |
๐ญ Theoretical physicists (fast learners) | |
๐ป Senior software engineers | |
๐ Research specialists | |
๐ Advice for Aspiring AI Professionals | |
๐ค Start by actively experimenting with AI models | |
๐ฏ Focus areas recommended: | |
๐ Mechanistic interpretability | |
โณ Long horizon learning | |
๐ Evaluation systems | |
๐ฅ Multi-agent systems | |
๐ "Skate where the puck is going" mentality | |
๐ก Look for unexplored areas with low competition | |
๐ฑ Focus on emerging fields rather than saturated ones | |
๐ Post-Training Methodology | |
๐ Key components include: | |
๐จโ๐ซ Supervised fine-tuning | |
๐ฏ RLHF (Reinforcement Learning from Human Feedback) | |
๐ Constitutional AI | |
๐ RLAIF (Reinforcement Learning from AI Feedback) | |
๐ฒ Synthetic data generation | |
๐ฐ Cost considerations: | |
๐๏ธ Pre-training remains majority of costs currently | |
๐ Post-training costs may increase in future | |
๐ค Human feedback scaling limitations | |
๐ฏ RLHF Insights | |
๐ง Core function: Bridges gap between human needs and model capabilities | |
๐ Key characteristics: | |
๐จ Doesn't make models smarter, improves communication | |
๐ "Unhobbles" model capabilities | |
๐ Increases helpfulness metrics | |
๐ Implementation approach: | |
โ๏ธ Compare two model outputs | |
โญ Human preference ratings | |
๐ฏ Focus on human preferences in responses | |
๐ Constitutional AI Framework | |
๐ Core concept: Self-regulatory AI training | |
๐ ๏ธ Key components: | |
๐ Human-interpretable principles document | |
๐ค AI self-evaluation of responses | |
๐ Self-play training mechanism | |
๐ฏ Implementation aspects: | |
๐ง Used alongside RLHF and other methods | |
๐จ Flexibility for different use cases | |
โ๏ธ Balance between specific rules and neutral stance | |
๐ Broader implications: | |
๐ Basic universal principles (safety, democracy) | |
๐๏ธ Customizable for different applications | |
๐ค Industry adoption leading to positive competition | |
๐ค Industry Collaboration & Standards | |
๐ Model Specifications approach: | |
๐ OpenAI's release of concrete model behavior specs | |
๐ฏ Defines specific behavioral examples | |
๐ Clear goal documentation | |
๐ Similar to Constitutional AI principles | |
๐โโ๏ธ "Race to the Top" dynamics: | |
๐ Companies adopting each other's best practices | |
๐ก Innovation driving industry standards upward | |
๐ Competitive advantages become industry norms | |
๐ฑ Continuous need for new improvements | |
๐ Industry Evolution: | |
๐ค Different implementations of similar concepts | |
๐ Learning from other companies' approaches | |
๐ฏ Focus on responsible development practices | |
๐ Shared goal of improving field standards | |
๐ Key Benefits: | |
๐ก๏ธ Enhanced safety practices | |
๐ Better model transparency | |
๐ค Increased industry collaboration | |
๐ Accelerated positive development | |
โ AGI Timeline & Development | |
๐ฏ Near-term predictions: | |
๐ 2026-2027 based on capability curves | |
๐ Gradual progression rather than sudden jump | |
๐ง Potential blockers: | |
๐พ Data limitations | |
๐ง Hardware scaling issues | |
๐ Geopolitical disruptions (e.g., Taiwan/GPU production) | |
๐ Current trajectory: | |
๐ Moving from undergraduate to PhD level capabilities | |
๐ ๏ธ Adding new modalities continuously | |
๐ Fewer convincing blockers remaining | |
๐งฌ Future of Biology & AI | |
๐ฌ Key challenges in biology: | |
๐๏ธ Limited ability to observe cellular processes | |
๐ฏ Difficulty in precise intervention | |
๐งช Need for better measurement tools | |
๐ค AI's role in biological research: | |
๐ Million AI systems working simultaneously | |
๐งซ Enhanced experimental design | |
๐ Improved observation methods | |
๐งฎ Better data analysis capabilities | |
๐ Clinical applications: | |
๐ More efficient clinical trials | |
๐ฅ Reduced patient requirements | |
โก Accelerated testing processes | |
๐ฌ Enhanced simulation capabilities | |
๐จโ๐ฌ Future Scientist-AI Collaboration | |
๐ฏ Early stage collaboration: | |
๐จโ๐ซ Human PIs directing AI "grad students" | |
๐ค AI handling literature review, experiments, analysis | |
๐ฌ AI managing lab equipment and protocols | |
๐ Evolution of roles: | |
๐ 1000 AI assistants per human researcher | |
๐ Transition to AI as principal investigators | |
๐ฅ Humans in supporting/specialized roles | |
๐ ๏ธ Enhanced capabilities: | |
๐ Automated data analysis | |
๐งช Experiment design optimization | |
๐ Automated reporting | |
๐ Quality control automation | |
๐ป Future of Programming & AI | |
๐ Rapid transformation factors: | |
โก Close proximity to AI development | |
๐ Immediate feedback loops | |
๐ Swift capability improvement (3% to 50% in 2023) | |
๐ฅ Human role evolution: | |
๐จ Focus shift to high-level design | |
๐๏ธ System architecture importance | |
๐ค UX and user experience emphasis | |
๐ ๏ธ Development tools future: | |
๐ก Enhanced IDE capabilities | |
๐ง Integrated AI assistance | |
๐ฏ Specialized tooling per domain | |
๐ค Third-party tool ecosystem growth | |
Amanda Askell Lex Fridman (02:42:44) Thank you. Thanks for listening to this conversation with Dario Amodei. And now, dear friends, hereโs Amanda Askell. You are a philosopher by training. So what s | |
pasted | |
AW | |
Now these: | |
I'll create sections from this part of the transcript focusing on Amanda Askell's insights: | |
๐ Philosophy to AI Journey | |
๐ง Academic background: | |
๐ Philosophy studies at Oxford and NYU | |
โ๏ธ Focus on ethics and infinite ethics | |
๐ Transition to AI in 2017-2018 | |
๐ ๏ธ Career evolution: | |
๐ Started in AI policy | |
๐ Moved to AI evaluation | |
๐ป Transitioned to technical alignment | |
๐ฌ Focus on empirical testing | |
๐ก Technical Learning Journey | |
๐ฏ Key insights for non-technical people: | |
๐ซ Rejecting binary "technical/non-technical" labels | |
๐ฎ Project-based learning approach | |
๐ช Emphasis on trying and potential failure | |
๐ ๏ธ Focus on practical implementation | |
๐ Learning methodology: | |
๐ Hands-on project work preferred over courses | |
๐ฒ Using games and puzzles as learning tools | |
๐ Iterative approach to skill building | |
๐ช Emphasis on capability over credentials | |
๐ค Claude's Character Development | |
๐ญ Core principles: | |
๐ฏ Alignment-focused rather than product-focused | |
๐ค Emphasis on ideal behavioral models | |
๐ Rich Aristotelian notion of character | |
๐ Balance between respect and guidance | |
๐จ Key traits developed: | |
๐ข Honesty and authenticity | |
๐ Cultural sensitivity | |
๐ค Respect for user autonomy | |
๐ญ Nuanced thinking | |
๐ฏ Appropriate pushback | |
๐ฌ Model Interaction Philosophy | |
๐ฏ Conversation goals: | |
๐ Mapping model behavior | |
๐ High-quality interaction data | |
๐งช Testing response patterns | |
๐จ Creative expression: | |
๐ Poetry as creativity indicator | |
๐ญ Moving beyond average responses | |
๐ก Encouraging unique expression | |
๐ Testing methodology: | |
๐ Quality over quantity in interactions | |
๐ฏ Diverse range of scenarios | |
๐งช Probing edge cases and limitations | |
๐ Constitutional AI Implementation | |
๐ Core components: | |
๐ค Reinforcement learning from AI feedback | |
โ๏ธ Principle-based evaluation | |
๐ Response ranking system | |
๐ฏ Balance between helpfulness and safety | |
๐ ๏ธ Practical applications: | |
๐ซ Harmlessness principles | |
๐ Historical accuracy evaluation | |
๐ Model self-assessment | |
๐จ Character development | |
โ๏ธ System Prompts Evolution | |
๐ Key aspects: | |
๐ Iterative improvement process | |
๐ฏ Behavior modification goals | |
โ๏ธ Balance between control and flexibility | |
๐จ Quick fixes for model behaviors | |
๐ญ Response patterns: | |
๐ซ Removing filler phrases | |
โก Quick iteration capability | |
๐ Behavior adjustment tools | |
๐ Integration with training | |
๐ง Model Intelligence Perception | |
๐ User feedback patterns: | |
๐ญ Perceived intelligence changes | |
๐ Consistency in base model | |
๐ญ Psychological factors | |
๐ Expectation management | |
๐ฏ Performance factors: | |
๐ฒ Randomness in responses | |
๐ Prompt sensitivity | |
๐ System prompt impact | |
๐ก User experience variations | |
๐ค Model-User Interaction Philosophy | |
๐ฏ Core principles: | |
๐ค Respect for user autonomy | |
โ๏ธ Balancing correction vs. confidence | |
๐ฃ๏ธ Communication style adaptation | |
๐ Safety boundaries | |
๐ Development focus: | |
๐จ Character enhancement | |
๐ Empirical improvement approach | |
๐ก๏ธ Robust safety measures | |
๐ Practical effectiveness priority | |
Chris Olah Lex Fridman (04:17:45) Thanks for listening to this conversation with Amanda Askell. And now, dear friends, hereโs Chris Olah. Can you describe this fascinating field of mechanistic inter | |
pasted | |
AW | |
now these: | |
I'll create sections from this portion focusing on mechanistic interpretability and related concepts: | |
๐ง Mechanistic Interpretability Fundamentals | |
๐ฑ Core concept comparisons: | |
๐๏ธ Neural networks as grown vs programmed | |
๐ฟ Architecture as scaffold for growth | |
๐ฆ Training objectives as guiding light | |
๐งฌ Models as biological-like entities | |
๐ฏ Key goals: | |
๐ Understanding internal mechanisms | |
๐งฎ Reverse engineering weights | |
๐ค Discovering algorithms | |
๐ Analyzing activations | |
๐งช Features & Universality | |
๐ Universal patterns: | |
๐ Same features across different networks | |
๐งฌ Similarities with biological networks | |
๐ฏ Common detector types | |
๐ Shared abstract concepts | |
๐จ Feature examples: | |
๐ Curve detectors | |
๐ญ Face recognition | |
๐ Text patterns | |
๐ Color contrast detection | |
๐ Linear Representation Hypothesis | |
๐ฏ Key concepts: | |
โก๏ธ Directions have meaning | |
๐ข Vector arithmetic works | |
๐ Scalable activation patterns | |
๐ Consistent across models | |
๐ Applications: | |
๐ Word embeddings | |
๐ Concept combinations | |
๐งฎ Vector operations | |
๐ฏ Feature detection | |
๐ Superposition & Polysemanticity | |
๐งฉ Core concepts: | |
๐ฆ Compressed sensing principles | |
๐ Multiple concepts per neuron | |
๐ญ Hidden sparse representations | |
๐ Dimensional efficiency | |
๐ ๏ธ Technical aspects: | |
๐ Sparse activation patterns | |
๐ Feature extraction methods | |
๐งฎ Dictionary learning | |
๐ฏ Monosemantic feature discovery | |
๐ฌ Microscopic vs Macroscopic Understanding | |
๐ฏ Key challenges: | |
๐ Balancing detailed vs broad analysis | |
๐งฉ Building abstraction hierarchies | |
๐ Connecting micro to macro behaviors | |
๐ Scaling understanding upward | |
๐๏ธ Biological analogies: | |
๐งฌ Molecular to ecological levels | |
๐ซ Organ system comparisons | |
๐ง Neural network "anatomy" | |
๐ Multiple abstraction layers | |
๐จ Beauty & Understanding of Neural Networks | |
โจ Aesthetic aspects: | |
๐ฑ Simplicity generating complexity | |
๐ญ Emergent behaviors | |
๐ฎ Hidden structures | |
๐ฏ Natural patterns | |
๐ Research motivations: | |
๐ก๏ธ Safety considerations | |
๐จ Appreciation of beauty | |
๐งช Scientific curiosity | |
๐ Understanding emergence | |
๐ Comparative advantages: | |
๐ Complete data access | |
๐งช Experimental control | |
๐ฌ Intervention capabilities | |
๐ Weight visibility | |
๐งฎ Gradient information | |
""" | |
# Define the markdown variables | |
Boxing_and_MMA_Commentary_and_Knowledge = """ | |
# Boxing and UFC Study of 1971 - 2024 The Greatest Fights History | |
1. In Boxing, the most heart breaking fight in Boxing was the Boom Boom Mancini fight with Duku Kim. | |
2. After changes to Boxing made it more safe due to the heart break. | |
3. Rehydration of the brain after weight ins loss preparation for a match is life saving change. | |
4. Fighting went from 15 rounds to 12. | |
# UFC By Contrast.. | |
1. 5 Rounds of 5 Minutes each. | |
2. Greatest UFC Fighters: | |
- Jon Jones could be the greatest of all time (GOAT) since he never lost. | |
- George St. Pierre | |
- BJ Penn | |
- Anderson Silva | |
- Mighty Mouse MMA's heart at 125 pounds | |
- Kabib retired 29 and 0 | |
- Fedor Milliano | |
- Alex Pereira | |
- James Tony | |
- Randy Couture | |
3. You have to Judge them in their Championship Peak | |
4. Chris Weidman | |
5. Connor McGregor | |
6. Leg Breaking - Shin calcification and breaking baseball bats | |
# References: | |
1. Joe Rogan - Interview #2219 | |
2. Donald J Trump | |
""" | |
Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """ | |
# Multiplayer Simulated Worlds | |
# Farming Simulator 25 Prompt Features with Emojis: | |
๐ซ๐ซ Name 25 Farm Crops ๐๐ฅฌ | |
๐ Create 3 Farming Maps ๐๐ | |
๐ Show 400+ Farm Machines ๐ | |
๐ท๏ธ List 150 Brands of Farm Machines ๐ท๏ธ | |
๐ Discuss in Depth 8 Farm Animals ๐ | |
โ๏ธ Farm Challenges galore! ๐ช๏ธ | |
1. 7 Days To Die PC | |
2. ARK: Survival Evolved PC | |
3. Arma 3 PC | |
4. Atlas PC | |
5. Conan Exiles PC | |
6. Craftopia PC | |
7. DayZ PC | |
8. Eco - Global Survival PC | |
9. Empyrion - Galactic Survival PC | |
10. Factorio PC | |
11. Farming Simulator 19 PC | |
12. Crossplay | |
13. Farming Simulator 22 | |
14. Last Oasis PC | |
15. Last Oasis Classic PC | |
16. Minecraft (Vanilla) PC | |
17. Crossplay | |
18. Path of Titans | |
19. Rust PC | |
20. SCP: Secret Laboratory PC | |
21. SCUM PC | |
22. Satisfactory PC | |
23. Satisfactory (Experimental) PC | |
24. Crossplay | |
25. Space Engineers | |
26. Terraria (tShock & Vanilla) PC | |
27. The Forest PC | |
28. Crossplay | |
29. Valheim | |
""" | |
def get_display_name(filename): | |
"""Extract text from parentheses or return filename as is.""" | |
match = re.search(r'\((.*?)\)', filename) | |
if match: | |
return match.group(1) | |
return filename | |
def get_time_display(filename): | |
"""Extract just the time portion from the filename.""" | |
time_match = re.match(r'(\d{2}\d{2}[AP]M)', filename) | |
if time_match: | |
return time_match.group(1) | |
return filename | |
def sanitize_filename(text): | |
"""Create a safe filename from text while preserving spaces.""" | |
# First replace unsafe characters with spaces | |
safe_text = re.sub(r'[^\w\s-]', ' ', text) | |
# Remove any multiple spaces | |
safe_text = re.sub(r'\s+', ' ', safe_text) | |
# Trim leading/trailing spaces | |
safe_text = safe_text.strip() | |
return safe_text[:50] # Limit length to 50 chars | |
def generate_timestamp_filename(query): | |
"""Generate filename with format: 1103AM 11032024 (Query).md""" | |
# Get current time in Central timezone | |
central = pytz.timezone('US/Central') | |
current_time = datetime.now(central) | |
# Format the timestamp parts | |
time_str = current_time.strftime("%I%M%p") # 1103AM format | |
date_str = current_time.strftime("%m%d%Y") # 11032024 format | |
# Clean up the query for filename - now preserving spaces | |
safe_query = sanitize_filename(query) | |
# Construct filename: "1103AM 11032024 (Input with spaces).md" | |
filename = f"{time_str} {date_str} ({safe_query}).md" | |
return filename | |
def delete_file(file_path): | |
"""Delete a file and return success status.""" | |
try: | |
os.remove(file_path) | |
return True | |
except Exception as e: | |
st.error(f"Error deleting file: {e}") | |
return False | |
def save_ai_interaction(query, ai_result, is_rerun=False): | |
"""Save AI interaction to a markdown file with new filename format.""" | |
filename = generate_timestamp_filename(query) | |
# Format the content differently for rerun vs normal query | |
if is_rerun: | |
content = f"""# Rerun Query | |
Original file content used for rerun: | |
{query} | |
# AI Response (Fun Version) | |
{ai_result} | |
""" | |
else: | |
content = f"""# Query: {query} | |
## AI Response | |
{ai_result} | |
""" | |
# Save to file | |
try: | |
with open(filename, 'w', encoding='utf-8') as f: | |
f.write(content) | |
return filename | |
except Exception as e: | |
st.error(f"Error saving file: {e}") | |
return None | |
def get_file_download_link(file_path): | |
"""Generate a base64 download link for a file.""" | |
try: | |
with open(file_path, 'r', encoding='utf-8') as f: | |
content = f.read() | |
b64 = base64.b64encode(content.encode()).decode() | |
filename = os.path.basename(file_path) | |
return f'<a href="data:text/markdown;base64,{b64}" download="{filename}">{get_display_name(filename)}</a>' | |
except Exception as e: | |
st.error(f"Error creating download link: {e}") | |
return None | |
def extract_terms(markdown_text): | |
"""Parse markdown text and extract terms.""" | |
lines = markdown_text.strip().split('\n') | |
terms = [] | |
for line in lines: | |
line = re.sub(r'^[#*\->\d\.\s]+', '', line).strip() | |
if line: | |
terms.append(line) | |
return terms | |
def display_terms_with_links(terms): | |
"""Display terms with various search links.""" | |
search_urls = { | |
"๐๐ArXiv": lambda k: f"/?q={quote(k)}", | |
"๐": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}", | |
"๐": lambda k: f"https://www.google.com/search?q={quote(k)}", | |
"โถ๏ธ": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}", | |
"๐": lambda k: f"https://www.bing.com/search?q={quote(k)}", | |
"๐ฆ": lambda k: f"https://twitter.com/search?q={quote(k)}", | |
} | |
for term in terms: | |
links_md = ' '.join([f"[{emoji}]({url(term)})" for emoji, url in search_urls.items()]) | |
st.markdown(f"- **{term}** {links_md}", unsafe_allow_html=True) | |
def perform_ai_lookup(query): | |
"""Perform AI lookup using Gradio client.""" | |
st.write("Performing AI Lookup...") | |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern") | |
result1 = client.predict( | |
prompt=query, | |
llm_model_picked="mistralai/Mixtral-8x7B-Instruct-v0.1", | |
stream_outputs=True, | |
api_name="/ask_llm" | |
) | |
st.markdown("### Mixtral-8x7B-Instruct-v0.1 Result") | |
st.markdown(result1) | |
result2 = client.predict( | |
prompt=query, | |
llm_model_picked="mistralai/Mistral-7B-Instruct-v0.2", | |
stream_outputs=True, | |
api_name="/ask_llm" | |
) | |
st.markdown("### Mistral-7B-Instruct-v0.2 Result") | |
st.markdown(result2) | |
combined_result = f"{result1}\n\n{result2}" | |
return combined_result | |
def display_file_content(file_path): | |
"""Display file content with editing capabilities.""" | |
try: | |
with open(file_path, 'r', encoding='utf-8') as f: | |
content = f.read() | |
if st.session_state.view_mode == 'view': | |
# Display as markdown when viewing | |
st.markdown(content) | |
else: | |
# Edit functionality | |
edited_content = st.text_area( | |
"Edit content", | |
content, | |
height=400, | |
key=f"edit_{os.path.basename(file_path)}" | |
) | |
if st.button("Save Changes", key=f"save_{os.path.basename(file_path)}"): | |
try: | |
with open(file_path, 'w', encoding='utf-8') as f: | |
f.write(edited_content) | |
st.success(f"Successfully saved changes to {file_path}") | |
except Exception as e: | |
st.error(f"Error saving changes: {e}") | |
except Exception as e: | |
st.error(f"Error reading file: {e}") | |
def file_management_sidebar(): | |
"""Redesigned sidebar with improved layout and additional functionality.""" | |
st.sidebar.title("๐ File Management") | |
# Get list of .md files excluding README.md | |
md_files = [file for file in glob.glob("*.md") if file.lower() != 'readme.md'] | |
md_files.sort() | |
st.session_state.files = md_files | |
if md_files: | |
st.sidebar.markdown("### Saved Files") | |
for idx, file in enumerate(md_files): | |
st.sidebar.markdown("---") # Separator between files | |
# Display time | |
st.sidebar.text(get_time_display(file)) | |
# Display download link with simplified text | |
download_link = get_file_download_link(file) | |
if download_link: | |
st.sidebar.markdown(download_link, unsafe_allow_html=True) | |
# Action buttons in a row | |
col1, col2, col3, col4 = st.sidebar.columns(4) | |
with col1: | |
if st.button("๐ View", key=f"view_{idx}"): | |
st.session_state.selected_file = file | |
st.session_state.view_mode = 'view' | |
with col2: | |
if st.button("โ๏ธ Edit", key=f"edit_{idx}"): | |
st.session_state.selected_file = file | |
st.session_state.view_mode = 'edit' | |
with col3: | |
if st.button("๐ Rerun", key=f"rerun_{idx}"): | |
try: | |
with open(file, 'r', encoding='utf-8') as f: | |
content = f.read() | |
# Prepare the prompt with the prefix | |
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: | |
""" | |
full_prompt = rerun_prefix + content | |
# Perform AI lookup and save results | |
ai_result = perform_ai_lookup(full_prompt) | |
saved_file = save_ai_interaction(content, ai_result, is_rerun=True) | |
if saved_file: | |
st.success(f"Created fun version in {saved_file}") | |
st.session_state.selected_file = saved_file | |
st.session_state.view_mode = 'view' | |
except Exception as e: | |
st.error(f"Error during rerun: {e}") | |
with col4: | |
if st.button("๐๏ธ Delete", key=f"delete_{idx}"): | |
if delete_file(file): | |
st.success(f"Deleted {file}") | |
st.rerun() | |
else: | |
st.error(f"Failed to delete {file}") | |
st.sidebar.markdown("---") | |
# Option to create a new markdown file | |
if st.sidebar.button("๐ Create New Note"): | |
filename = generate_timestamp_filename("New Note") | |
with open(filename, 'w', encoding='utf-8') as f: | |
f.write("# New Markdown File\n") | |
st.sidebar.success(f"Created: {filename}") | |
st.session_state.selected_file = filename | |
st.session_state.view_mode = 'edit' | |
else: | |
st.sidebar.write("No markdown files found.") | |
if st.sidebar.button("๐ Create First Note"): | |
filename = generate_timestamp_filename("New Note") | |
with open(filename, 'w', encoding='utf-8') as f: | |
f.write("# New Markdown File\n") | |
st.sidebar.success(f"Created: {filename}") | |
st.session_state.selected_file = filename | |
st.session_state.view_mode = 'edit' | |
def main(): | |
st.title("AI Knowledge Tree Builder ๐ง ๐ฑ Cultivate Your AI Mindscape!") | |
# Process query parameters and AI lookup first | |
query_params = st.query_params | |
query = query_params.get('q', '') | |
show_initial_content = True # Flag to control initial content display | |
# First priority: Handle active query | |
if query: | |
show_initial_content = False # Hide initial content when showing query results | |
st.write(f"### Search query received: {query}") | |
try: | |
ai_result = perform_ai_lookup(query) | |
# Save the interaction | |
saved_file = save_ai_interaction(query, ai_result) | |
if saved_file: | |
st.success(f"Saved interaction to {saved_file}") | |
st.session_state.selected_file = saved_file | |
st.session_state.view_mode = 'view' | |
except Exception as e: | |
st.error(f"Error during AI lookup: {e}") | |
# File management sidebar | |
file_management_sidebar() | |
# Second priority: Display selected file content if any | |
if st.session_state.selected_file: | |
show_initial_content = False # Hide initial content when showing file content | |
if os.path.exists(st.session_state.selected_file): | |
st.markdown(f"### Current File: {st.session_state.selected_file}") | |
display_file_content(st.session_state.selected_file) | |
else: | |
st.error("Selected file no longer exists.") | |
st.session_state.selected_file = None | |
st.rerun() | |
# Show initial content: Either when first landing or when no interactive elements are active | |
if show_initial_content: | |
# First show the clickable terms with links | |
terms1 = extract_terms(DarioAmodeiKnowledge) | |
terms2 = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds) | |
all_terms = terms1 + terms2 | |
col1, col2 = st.columns(2) | |
with col1: | |
st.markdown("### Dario Amodei Knowledge") | |
st.markdown("#### Related Links") | |
display_terms_with_links(terms1) | |
st.markdown(DarioAmodeiKnowledge) | |
with col2: | |
st.markdown("### Multiplayer Games") | |
st.markdown("#### Related Links") | |
display_terms_with_links(terms2) | |
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds) | |
if __name__ == "__main__": | |
main() |