Spaces:
Running
Running
import streamlit as st | |
import os | |
import glob | |
import re | |
import base64 | |
import pytz | |
import time | |
import streamlit.components.v1 as components | |
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 = '๐ณโจ๐ ๏ธ๐ค' | |
SidebarOutline="""๐ณ๐ค Designed with the following tenets: | |
1 ๐ฑ **Portability** - Universal access via any device & link sharing | |
2. โก **Speed of Build** - Rapid deployments < 2min to production | |
3. ๐ **Linkiness** - Programmatic access to AI knowledge sources | |
4. ๐ฏ **Abstractive** - Core stays lean isolating high-maintenance components | |
5. ๐ง **Memory** - Shareable flows deep-linked research paths | |
6. ๐ค **Personalized** - Rapidly adapts knowledge base to user needs | |
7. ๐ฆ **Living Brevity** - Easily cloneable, self modify data public share results. | |
""" | |
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 | |
} | |
) | |
st.sidebar.markdown(SidebarOutline) | |
# 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 = [] | |
BiologyAndLevel36MagicUsers=""" | |
0. Biology Core Rules and Future Exceptions | |
1. Central Dogma DNA RNA Protein | |
- Current CRISPR RNA editing ๐งช | |
- Research Gene therapy siRNA ๐ฌ | |
- Future Programmable genetics ๐ | |
2. Cell Origin | |
- Current iPSCs organoids ๐ฆ | |
- Research Synthetic cells ๐ฌ | |
- Future De novo cell creation ๐ | |
3. Form Function | |
- Current Bioprinting ๐ซ | |
- Research 4D printing ๐ฌ | |
- Future Self assembling structures ๐ | |
4. Homeostasis | |
- Current Artificial pancreas ๐ค | |
- Research Nanorobots ๐ฌ | |
- Future Autonomous regulation ๐ | |
5. Evolution | |
- Current Directed evolution ๐งซ | |
- Research Synthetic biology ๐ฌ | |
- Future Accelerated adaptation ๐ | |
6. Energy Conservation | |
- Current Biofuel cells โก | |
- Research Quantum biology ๐ฌ | |
- Future Biological perpetual motion ๐ | |
7. Cellular Life | |
- Current Organoid systems ๐ฎ | |
- Research Hybrid cells ๐ฌ | |
- Future Silicon based life ๐ | |
8. Inheritance Patterns | |
- Current Gene drives ๐งฉ | |
- Research Epigenetic control ๐ฌ | |
- Future Designed inheritance ๐ | |
9. Energy Requirements | |
- Current Metabolic engineering ๐ | |
- Research Synthetic photosynthesis ๐ฌ | |
- Future Zero energy life ๐ | |
10. Random Mutation | |
- Current Base editing ๐ฏ | |
- Research Mutation prediction ๐ฌ | |
- Future Controlled evolution ๐ | |
11. Carbon Based Life | |
- Current Alternative biochemistry ๐ | |
- Research Silicon biology ๐ฌ | |
- Future Non carbon life ๐ | |
12. Size Limitations | |
- Current Nanostructures ๐ | |
- Research Quantum biology ๐ฌ | |
- Future Scalable organisms ๐ | |
13. Species Interdependence | |
- Current Synthetic ecosystems ๐ฟ | |
- Research Artificial symbiosis ๐ฌ | |
- Future Independent life ๐ | |
14. Stimulus Response | |
- Current Brain computer interfaces ๐ง | |
- Research Neural engineering ๐ฌ | |
- Future Direct consciousness control ๐ | |
15. Development Complexity | |
- Current Accelerated growth ๐ฑ | |
- Research Development control ๐ฌ | |
- Future Instant maturation ๐ | |
16. Population Growth | |
- Current Population control ๐ | |
- Research Sustainable ecosystems ๐ฌ | |
- Future Perfect equilibrium ๐ | |
17. Energy Flow | |
- Current Enhanced photosynthesis ๐ | |
- Research Energy optimization ๐ฌ | |
- Future Perpetual systems ๐ | |
18. Environmental Adaptation | |
- Current Climate resistance ๐ | |
- Research Universal adaptation ๐ฌ | |
- Future Environment independence ๐ | |
19. Genetic Inheritance | |
- Current Gene editing ๐งฌ | |
- Research Trait programming ๐ฌ | |
- Future Perfect inheritance ๐ | |
20. Reproduction | |
- Current Artificial wombs ๐ถ | |
- Research Cloning advances ๐ฌ | |
- Future Asexual human reproduction ๐ | |
21. Aging Death | |
- Current Longevity therapy โฐ | |
- Research Age reversal ๐ฌ | |
- Future Biological immortality ๐ | |
""" | |
AITopicsToInnovate1=""" | |
1. Major AI Industry Players ๐ | |
1. Research Leaders ๐ฏ | |
- OpenAI: GPT-4 DALL-E Foundation Models ๐ต | |
- Google: PaLM Gemini LLMs ๐ฆ | |
- Anthropic: Claude Constitutional AI โก | |
- Meta: LLaMA Open Source LLMs ๐ค | |
- xAI: Grok Conversational AI ๐ค | |
2. Technical AI Development ๐ ๏ธ | |
1. Architecture Advances ๐ซ | |
- Transformer Models Attention Mechanisms ๐ง | |
- Mixture of Experts MoE Architecture ๐ช | |
- Sparse Neural Networks ๐ธ๏ธ | |
- Multi-modal LLM Systems ๐ | |
- Flash Attention Optimization โ๏ธ | |
2. Training Methodologies ๐ | |
- LLM Supervised Fine-tuning ๐จโ๐ซ | |
- RLHF Reward Models ๐ค | |
- Constitutional AI Training ๐ | |
- RLAIF Feedback Models ๐ | |
- Synthetic Data LLM Training ๐ฒ | |
- Chain of Thought Prompting ๐งฉ | |
- Tree of Thoughts Reasoning ๐ณ | |
3. Post-Training Implementation ๐ง | |
- Neural Network Distillation ๐งช | |
- LLM Quantization Methods ๐ | |
- Neural Network Pruning โ๏ธ | |
- Knowledge Distillation Transfer ๐ | |
- Few-shot LLM Learning ๐ฏ | |
3. Mechanistic Interpretability ๐ฌ | |
1. Core Concepts ๐ก | |
- Neural Network Growth Analysis ๐ฑ | |
- LLM Architecture Analysis ๐๏ธ | |
- Training Loss Optimization ๐จ | |
- Neural Network Analogies ๐งฌ | |
2. Technical Features ๐ | |
- LLM Linear Representations โก๏ธ | |
- Neural Vector Arithmetic ๐ข | |
- Neural Activation Patterns ๐ | |
- LLM Feature Detection ๐ | |
- Neural Sparse Autoencoders ๐ญ | |
3. Network Analysis ๐ต๏ธ | |
- LLM Induction Heads ๐ | |
- Transformer Attention Analysis ๐ช | |
- Neural Circuit Analysis ๐ | |
- LLM Feature Visualization ๐ | |
- Neural Concept Directions ๐ณ | |
4. Future AI Developments ๐ | |
1. AGI Timeline โฐ | |
- AGI Capability Projections ๐ | |
- Neural Hardware Scaling ๐พ | |
- LLM Training Data Limits ๐ | |
- AI Compute Resources ๐บ๏ธ | |
2. Integration Fields ๐ก | |
- AI Biology Integration ๐ฎ | |
- AI Drug Discovery Systems ๐ | |
- AI Clinical Trial Analysis ๐ฅ | |
- AI Code Generation ๐คน | |
- AI Scientific Discovery ๐งฎ | |
5. Industry Best Practices ๐ | |
1. AI Team Building ๐ข | |
- AI Talent Development ๐ฅ | |
- AI Research Alignment ๐ช | |
- AI Team Scaling ๐ | |
- AI Research Culture ๐ | |
2. AI Research Qualities ๐ | |
- AI Research Methodology ๐งญ | |
- AI Experimentation Protocols ๐๏ธ | |
- AI Innovation Thinking ๐ซ | |
- AI Testing Framework โ๏ธ | |
3. AI Safety Standards ๐ก๏ธ | |
- LLM Behavioral Specifications ๐ | |
- AI Safety Guidelines ๐ฎ | |
- AI Ethics Framework โ๏ธ | |
- AI Industry Standards ๐คฒ | |
6. Emerging Research Areas ๐ฎ | |
1. Technical Focus ๐ฏ | |
- LLM Long Context Learning โณ | |
- LLM Multi-agent Interaction ๐พ | |
- AI Evaluation Metrics ๐ | |
- Neural Interpretability Methods ๐ญ | |
2. AI Applications ๐ผ | |
- AI Automated Research ๐งซ | |
- AI Code Synthesis โจ๏ธ | |
- AI Biological Modeling ๐งฏ | |
- AI Medical Diagnostics ๐ | |
7. Model Intelligence ๐งฟ | |
1. LLM System Development ๐ช | |
- LLM Prompt Engineering ๐ | |
- LLM Response Generation โ๏ธ | |
- LLM Behavioral Training ๐น | |
- LLM Personality Development ๐ช | |
2. LLM User Interaction ๐ญ | |
- LLM Autonomy Alignment ๐ช | |
- LLM Safety Boundaries ๐ | |
- LLM Communication Patterns ๐ฃ๏ธ | |
- LLM Performance Tuning ๐ข | |
""" | |
Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """ | |
0. Fantasy Domain Introduction | |
1. Setting the Scene | |
- Current Create a high-fantasy realm with unique ecosystems, magical phenomena, and cultural diversity ๐๏ธ | |
- Research Add domain-specific entities like mythical creatures, enchanted terrains, or ancient artifacts ๐งโโ๏ธ | |
- Future Fully AI-generated interactive worldbuilding ๐ | |
2. Archetypal Overview | |
- Current Write a summary of a classic D&D character archetype ๐ก๏ธ | |
- Research Add roles, special abilities, and motivations for NPC creation ๐ฎ | |
- Future AI-enhanced roleplay character dynamics ๐ | |
3. Entity-Focused Narrative Creation | |
1. Monster Mythology | |
- Current Create monsters with unique traits like โCrimson Obelisk Wurmโ ๐ | |
- Research Add lore and origin stories with detailed classifications ๐ฌ | |
- Future Dynamic AI monster lore generators ๐ | |
2. Artifact Legacy | |
- Current Describe legendary artifacts like โThe Aetherflame Prismโ ๐งโโ๏ธ | |
- Research Add historical narratives and effects on wielders ๐ฌ | |
- Future AI-designed item crafting ๐ | |
3. Heroic Figures | |
- Current Write backstories for heroic figures like โSyran Stormbladeโ โ๏ธ | |
- Research Integrate figures into broader campaigns and their achievements ๐ฌ | |
- Future Procedurally generated heroes ๐ | |
4. Immersive Dialogues and Roleplay | |
1. NPC Conversations | |
- Current Generate realistic NPC dialogues like in โThe Ghostwood Forestโ ๐จ๏ธ | |
- Research Add depth to NPC motivations and interactions ๐ฌ | |
- Future AI-led adaptive NPC behavior ๐ | |
2. Villain Confrontations | |
- Current Design confrontations with unique villains like โEldrazar the Timelessโ ๐น | |
- Research Layer villains with complex personalities and backstories ๐ฌ | |
- Future AI-driven antagonist strategy generation ๐ | |
5. World-Building | |
1. Cultural Narratives | |
- Current Describe civilizations like โThe Emberkinโ ๐ | |
- Research Add societal structures and traditions ๐ฌ | |
- Future AI-created evolving societies ๐ | |
2. Mythic Locations | |
- Current Create locations like โThe Whispering Wastesโ ๐๏ธ | |
- Research Integrate locations into broader world lore ๐ฌ | |
- Future Fully explorable AI worlds ๐ | |
3. Dimensional Realms | |
- Current Design parallel dimensions like โThe Veil of Shadowsโ ๐ | |
- Research Add magical laws and inhabitants ๐ฌ | |
- Future AI-generated multiverses ๐ | |
6. Quests and Campaigns | |
1. Campaign Arcs | |
- Current Design multi-part campaigns like retrieving โThe Obsidian Crownโ ๐ฏ | |
- Research Add NPC, obstacle, and objective integration ๐ฌ | |
- Future AI-created campaign blueprints ๐ | |
2. Encounter Design | |
- Current Create encounters like facing โThe Frostbane Golemโ ๐ง | |
- Research Add detailed strategies and reward systems ๐ฌ | |
- Future AI-led encounter simulations ๐ | |
3. Legendary Betrayals | |
- Current Write scenarios with plot twists, e.g., โThane Vorthakโs betrayalโ ๐ค | |
- Research Add motivations and dramatic tension ๐ฌ | |
- Future AI-generated unpredictable twists ๐ | |
7. AI Collaboration for Dual Perspectives | |
1. Scene Duality | |
- Current Generate battle scenes like adventurers vs. a Beholder ๐ก๏ธ | |
- Research Rewrite scenes from different perspectives ๐ฌ | |
- Future AI-enhanced multi-perspective storytelling ๐ | |
2. Tag Comparison | |
- Current Classify entities like MON, LOC, ART using NER tags ๐ท๏ธ | |
- Research Refine classifications with AI collaboration ๐ฌ | |
- Future Real-time AI entity extraction ๐ | |
8. Experimental Storytelling Techniques | |
1. Lore Fusion | |
- Current Combine legends like โStormcallersโ and โVoidseersโ ๐ | |
- Research Create shared histories with dynamic lore layers ๐ฌ | |
- Future AI-driven mythos merging ๐ | |
2. Procedural Creativity | |
- Current Generate tables of random D&D entities ๐ | |
- Research Add adaptive tags for dynamic storytelling ๐ฌ | |
- Future Procedural AI entity generation ๐ | |
9. Advanced NER Applications | |
1. Custom Tags | |
- Current Create tags like SPELL and TRAP for dungeon-specific entities ๐ | |
- Research Train AI on niche tags for unique entity extraction ๐ฌ | |
- Future AI-driven custom tag creation ๐ | |
2. Entity Extraction | |
- Current Extract entities from passages like โThe Sunken Cryptsโ ๐๏ธ | |
- Research Add advanced AI classification accuracy ๐ฌ | |
- Future Automated fine-tuning for AI models ๐ | |
3. Dimensional Entities | |
- Current Classify niche entities like โVoidwalkersโ ๐ | |
- Research Train models for multi-dimensional lore ๐ฌ | |
- Future AI multiverse exploration ๐ | |
Active Multiplayer Games 2024 ๐ฎ | |
1 Traditional MMORPGs ๐ก๏ธ | |
1.1 Major MMORPGs ๐ฐ | |
- Final Fantasy XIV Dawntrail 2024 โ๏ธ | |
- Advanced Job System Rework ๐ญ | |
- Cross Platform Integration ๐ช | |
- New Housing Districts ๐๏ธ | |
- World of Warcraft 2024 Season ๐ฒ | |
- Dragon Combat System ๐ฆ | |
- Cross Faction Features โ๏ธ | |
- Mythic Plus Seasons ๐ | |
- Elder Scrolls Online Gold Road ๐๏ธ | |
- Dynamic Event System ๐ | |
- Housing Construction ๐๏ธ | |
- Champion System 2.0 ๐ | |
- Lost Ark Western T4 Update โก | |
- Legion Raid Content ๐พ | |
- Island Adventure System ๐๏ธ | |
- Class Balance Rework ๐ฐ | |
- Black Desert Online Remaster ๐ช | |
- Combat System Update ๐ฏ | |
- Node Empire System ๐น | |
- Life Skill Evolution ๐ณ | |
1.2 Emerging MMORPGs ๐ | |
- Throne and Liberty Launch ๐ | |
- Weather Combat System ๐ฆ๏ธ | |
- Territory Wars ๐บ๏ธ | |
- Transformation System ๐ | |
- Pax Dei Medieval MMO โ๏ธ | |
- City Management ๐ฐ | |
- Faith Based Magic โจ | |
- Global Trading ๐ | |
- Blue Protocol Western Release ๐ | |
- Action Combat Design ๐ญ | |
- Class Change System โก | |
- Dungeon Scaling ๐ผ | |
2 Survival MMOs ๐น | |
2.1 Established Survival ๐ก๏ธ | |
- Rust 2024 Updates ๐ฆพ | |
- Electricity Programming ๐ก | |
- Vehicle System Update ๐ | |
- Automated Defenses โก | |
- ARK Survival Ascended ๐ฆ | |
- Cross ARK System ๐ | |
- Creature Breeding 2.0 ๐ฅ | |
- Base Defense Network ๐ฐ | |
- DayZ 2024 Content ๐ง | |
- Medical System Update ๐ | |
- Disease Mechanics ๐ฆ | |
- Base Building 2.0 ๐๏ธ | |
- 7 Days to Die Alpha 22 ๐๏ธ | |
- Physics Engine Update ๐ฅ | |
- AI Pathfinding System ๐ง | |
- Vehicle Customization ๐ | |
2.2 New Survival MMOs ๐ | |
- Once Human Launch ๐งฌ | |
- Mutation System ๐งช | |
- Base Building Tech ๐ญ | |
- Weather Impact System ๐ช๏ธ | |
- Nightingale Release ๐ | |
- Portal Realm System ๐ | |
- Victorian Crafting ๐ฉ | |
- Fae World Design ๐ง | |
3 Hybrid MMOs ๐ฏ | |
3.1 Looter Shooters ๐ซ | |
- Destiny 2 2024 Season ๐ธ | |
- Build System 3.0 ๐ ๏ธ | |
- Raid Mechanics โญ | |
- Season Structure ๐ | |
- The Division 2 Year 6 ๐๏ธ | |
- Loadout Expansion ๐ | |
- Dark Zone Update ๐ | |
- Manhunt System ๐ฏ | |
- Warframe 2024 Update ๐ค | |
- Movement Tech 2.0 ๐ | |
- Mod System Rework โ๏ธ | |
- Open World Expansion ๐ | |
3.2 Action RPG MMOs ๐ซ | |
- Path of Exile 2 Beta ๐ | |
- Gem System Rework ๐ซ | |
- New Skill Tree ๐ฒ | |
- League Content ๐ | |
- Diablo 4 Season Structure ๐ | |
- Season Journey System ๐ญ | |
- World Boss Events ๐ฒ | |
- PvP Territories ๐ก๏ธ | |
4 Simulation MMOs ๐ | |
4.1 Space Simulation ๐ | |
- EVE Online 2024 ๐ธ | |
- Corporation Warfare ๐ดโโ ๏ธ | |
- Market System Update ๐ | |
- Fleet Operations ๐ข | |
- Elite Dangerous Update ๐ | |
- Ground Combat System ๐จโ๐ | |
- Fleet Carrier Content โญ | |
- Planet Exploration ๐ช | |
- Star Citizen Alpha ๐ธ | |
- Persistent Universe ๐ | |
- Ship Combat Update โ๏ธ | |
- Trading System 2.0 ๐ฐ | |
4.2 World Simulation ๐ | |
- New World Eternal ๐บ๏ธ | |
- Territory System ๐ฐ | |
- Crafting Update ๐ ๏ธ | |
- War System 2.0 โ๏ธ | |
- Albion Online 2024 ๐น | |
- Guild Warfare Update โ๏ธ | |
- Economy System 2.0 ๐ฐ | |
- Territory Control ๐ฐ | |
5 Unique Multiplayer Games ๐ฒ | |
5.1 Adventure Multiplayer ๐บ๏ธ | |
- Sea of Thieves 2024 โต | |
- Ship Combat Physics ๐ | |
- Crew Management ๐ดโโ ๏ธ | |
- World Events ๐ช | |
- Valheim Updates โก | |
- Building System 2.0 ๐๏ธ | |
- Boss Progression ๐น | |
- Exploration Update ๐บ๏ธ | |
5.2 Combat Focused ๐ก๏ธ | |
- Mordhau 2024 โ๏ธ | |
- Combat Physics Update ๐คบ | |
- Map System Rework ๐ฐ | |
- Tournament System ๐ | |
- For Honor Year 8 ๐ก๏ธ | |
- Faction War Update โ๏ธ | |
- Hero Rework System ๐ญ | |
- Seasonal Content ๐ | |
6 Upcoming 2024 Games ๐ฎ | |
6.1 Launching Soon ๐ | |
- Gray Zone Warfare ๐๏ธ | |
- Tactical Systems ๐ฏ | |
- Base Operations ๐ข | |
- Territory Control ๐บ๏ธ | |
- Fractured Online ๐ | |
- City Building ๐๏ธ | |
- Knowledge System ๐ | |
- Player Economy ๐ฐ | |
6.2 In Development ๐ ๏ธ | |
- Ashes of Creation ๐ฐ | |
- Node System ๐ฑ | |
- Castle Siege โ๏ธ | |
- Caravan System ๐ช | |
- Pantheon Rise of the Fallen ๐ | |
- Climate System ๐ฆ๏ธ | |
- Group Content Focus ๐ฅ | |
- Perception System ๐๏ธ | |
""" | |
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 extract_urls(text): | |
try: | |
date_pattern = re.compile(r'### (\d{2} \w{3} \d{4})') | |
abs_link_pattern = re.compile(r'\[(.*?)\]\((https://arxiv\.org/abs/\d+\.\d+)\)') | |
pdf_link_pattern = re.compile(r'\[โฌ๏ธ\]\((https://arxiv\.org/pdf/\d+\.\d+)\)') | |
title_pattern = re.compile(r'### \d{2} \w{3} \d{4} \| \[(.*?)\]') | |
date_matches = date_pattern.findall(text) | |
abs_link_matches = abs_link_pattern.findall(text) | |
pdf_link_matches = pdf_link_pattern.findall(text) | |
title_matches = title_pattern.findall(text) | |
# markdown with the extracted fields | |
markdown_text = "" | |
for i in range(len(date_matches)): | |
date = date_matches[i] | |
title = title_matches[i] | |
abs_link = abs_link_matches[i][1] | |
pdf_link = pdf_link_matches[i] | |
markdown_text += f"**Date:** {date}\n\n" | |
markdown_text += f"**Title:** {title}\n\n" | |
markdown_text += f"**Abstract Link:** [{abs_link}]({abs_link})\n\n" | |
markdown_text += f"**PDF Link:** [{pdf_link}]({pdf_link})\n\n" | |
markdown_text += "---\n\n" | |
return markdown_text | |
except: | |
st.write('.') | |
return '' | |
# HTML5 based Speech Synthesis (Text to Speech in Browser) | |
def SpeechSynthesis(result): | |
documentHTML5=''' | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Read It Aloud</title> | |
<script type="text/javascript"> | |
function readAloud() { | |
const text = document.getElementById("textArea").value; | |
const speech = new SpeechSynthesisUtterance(text); | |
window.speechSynthesis.speak(speech); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>๐ Read It Aloud</h1> | |
<textarea id="textArea" rows="10" cols="80"> | |
''' | |
documentHTML5 = documentHTML5 + result | |
documentHTML5 = documentHTML5 + ''' | |
</textarea> | |
<br> | |
<button onclick="readAloud()">๐ Read Aloud</button> | |
</body> | |
</html> | |
''' | |
components.html(documentHTML5, width=1280, height=300) | |
def display_terms_with_links(terms): | |
"""Display terms with various search links.""" | |
search_urls = { | |
"๐๐ArXiv": lambda k: f"/?q={quote(k)}", # Academic/paper theme | |
"๐ฎ<sup>Google</sup>": lambda k: f"https://www.google.com/search?q={quote(k)}", # Crystal ball for search | |
"๐บ<sup>Youtube</sup>": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}", # TV for videos | |
"๐ญ<sup>Bing</sup>": lambda k: f"https://www.bing.com/search?q={quote(k)}", # Telescope for search | |
"๐ก<sup>Truth</sup>": lambda k: f"https://truthsocial.com/search?q={quote(k)}", # Light bulb for insight | |
"๐ฑX": lambda k: f"https://twitter.com/search?q={quote(k)}", # Phone for social media | |
} | |
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 search_arxiv(query): | |
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 | |
return responseall | |
# Function to generate a filename based on prompt and time (because names matter ๐) | |
def generate_filename(prompt, file_type): | |
central = pytz.timezone('US/Central') | |
safe_date_time = datetime.now(central).strftime("%m%d_%H%M") | |
safe_prompt = re.sub(r'\W+', '_', prompt)[:90] | |
return f"{safe_date_time}_{safe_prompt}.{file_type}" | |
# Function to create and save a file (and avoid the black hole of lost data ๐ณ) | |
def create_file(filename, prompt, response): | |
with open(filename, 'w', encoding='utf-8') as file: | |
file.write(prompt + "\n\n" + response) | |
def perform_ai_lookup(query): | |
start_time = time.strftime("%Y-%m-%d %H:%M:%S") | |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern") | |
response1 = client.predict( | |
query, | |
20, | |
"Semantic Search", | |
"mistralai/Mixtral-8x7B-Instruct-v0.1", | |
api_name="/update_with_rag_md" | |
) | |
Question = '### ๐ ' + query + '\r\n' # Format for markdown display with links | |
References = response1[0] | |
ReferenceLinks = extract_urls(References) | |
RunSecondQuery = True | |
results='' | |
if RunSecondQuery: | |
# Search 2 - Retrieve the Summary with Papers Context and Original Query | |
response2 = client.predict( | |
query, | |
"mistralai/Mixtral-8x7B-Instruct-v0.1", | |
True, | |
api_name="/ask_llm" | |
) | |
if len(response2) > 10: | |
Answer = response2 | |
SpeechSynthesis(Answer) | |
# Restructure results to follow format of Question, Answer, References, ReferenceLinks | |
results = Question + '\r\n' + Answer + '\r\n' + References + '\r\n' + ReferenceLinks | |
st.markdown(results) | |
st.write('๐Run of Multi-Agent System Paper Summary Spec is Complete') | |
end_time = time.strftime("%Y-%m-%d %H:%M:%S") | |
start_timestamp = time.mktime(time.strptime(start_time, "%Y-%m-%d %H:%M:%S")) | |
end_timestamp = time.mktime(time.strptime(end_time, "%Y-%m-%d %H:%M:%S")) | |
elapsed_seconds = end_timestamp - start_timestamp | |
st.write(f"Start time: {start_time}") | |
st.write(f"Finish time: {end_time}") | |
st.write(f"Elapsed time: {elapsed_seconds:.2f} seconds") | |
filename = generate_filename(query, "md") | |
create_file(filename, query, results) | |
return results | |
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("๐Run", 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.markdown("### 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(AITopicsToInnovate1) | |
terms2 = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds) | |
terms3 = extract_terms(BiologyAndLevel36MagicUsers) | |
all_terms = terms1 + terms2 + terms3 | |
col1, col2, col3, col4, col5, col6 = st.columns(6) | |
with col1: | |
st.markdown("#### AI Topics to Innovate With") | |
st.markdown(AITopicsToInnovate1) | |
with col2: | |
st.markdown("#### AI Agent Links") | |
display_terms_with_links(terms1) | |
with col3: | |
st.markdown("#### Biology Innovation with Data Science and AI Solutions") | |
st.markdown(BiologyAndLevel36MagicUsers) | |
with col4: | |
st.markdown("#### Biology Innovation Agent Links") | |
display_terms_with_links(terms3) | |
with col5: | |
st.markdown("#### Multiplayer Games and MMOs") | |
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds) | |
with col6: | |
st.markdown("#### Multiplayer Game and MMO Links") | |
display_terms_with_links(terms2) | |
if __name__ == "__main__": | |
main() |