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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import glob
|
| 6 |
+
import json
|
| 7 |
+
import base64
|
| 8 |
+
import zipfile
|
| 9 |
+
import random
|
| 10 |
+
import requests
|
| 11 |
+
import streamlit as st
|
| 12 |
+
import streamlit.components.v1 as components
|
| 13 |
+
import time
|
| 14 |
+
|
| 15 |
+
# If you do model inference via huggingface_hub:
|
| 16 |
+
# from huggingface_hub import InferenceClient
|
| 17 |
+
|
| 18 |
+
########################################################################################
|
| 19 |
+
# 1) GLOBAL CONFIG & PLACEHOLDERS
|
| 20 |
+
########################################################################################
|
| 21 |
+
BASE_URL = "https://huggingface.co/spaces/awacke1/MermaidMarkdownDiagramEditor"
|
| 22 |
+
BASE_URL = ""
|
| 23 |
+
|
| 24 |
+
PromptPrefix = "AI-Search: "
|
| 25 |
+
PromptPrefix2 = "AI-Refine: "
|
| 26 |
+
PromptPrefix3 = "AI-JS: "
|
| 27 |
+
|
| 28 |
+
roleplaying_glossary = {
|
| 29 |
+
"Core Rulebooks": {
|
| 30 |
+
"Dungeons and Dragons": ["Player's Handbook", "Dungeon Master's Guide", "Monster Manual"],
|
| 31 |
+
"GURPS": ["Basic Set Characters", "Basic Set Campaigns"]
|
| 32 |
+
},
|
| 33 |
+
"Campaigns & Adventures": {
|
| 34 |
+
"Pathfinder": ["Rise of the Runelords", "Curse of the Crimson Throne"]
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
transhuman_glossary = {
|
| 39 |
+
"Neural Interfaces": ["Cortex Jack", "Mind-Machine Fusion"],
|
| 40 |
+
"Cybernetics": ["Robotic Limbs", "Augmented Eyes"],
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
def process_text(text):
|
| 44 |
+
"""🕵️ process_text: detective style—prints lines to Streamlit for debugging."""
|
| 45 |
+
st.write(f"process_text called with: {text}")
|
| 46 |
+
|
| 47 |
+
def search_arxiv(text):
|
| 48 |
+
"""🔭 search_arxiv: pretend to search ArXiv, just prints debug."""
|
| 49 |
+
st.write(f"search_arxiv called with: {text}")
|
| 50 |
+
|
| 51 |
+
def SpeechSynthesis(text):
|
| 52 |
+
"""🗣 Simple logging for text-to-speech placeholders."""
|
| 53 |
+
st.write(f"SpeechSynthesis called with: {text}")
|
| 54 |
+
|
| 55 |
+
def process_image(image_file, prompt):
|
| 56 |
+
"""📷 Simple placeholder for image AI pipeline."""
|
| 57 |
+
return f"[process_image placeholder] {image_file} => {prompt}"
|
| 58 |
+
|
| 59 |
+
def process_video(video_file, seconds_per_frame):
|
| 60 |
+
"""🎞 Simple placeholder for video AI pipeline."""
|
| 61 |
+
st.write(f"[process_video placeholder] {video_file}, {seconds_per_frame} sec/frame")
|
| 62 |
+
|
| 63 |
+
API_URL = "https://huggingface-inference-endpoint-placeholder"
|
| 64 |
+
API_KEY = "hf_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
| 65 |
+
|
| 66 |
+
@st.cache_resource
|
| 67 |
+
def InferenceLLM(prompt):
|
| 68 |
+
"""🔮 Stub returning mock response for 'prompt'."""
|
| 69 |
+
return f"[InferenceLLM placeholder response to prompt: {prompt}]"
|
| 70 |
+
|
| 71 |
+
########################################################################################
|
| 72 |
+
# 2) GLOSSARY & FILE UTILITY
|
| 73 |
+
########################################################################################
|
| 74 |
+
@st.cache_resource
|
| 75 |
+
def display_glossary_entity(k):
|
| 76 |
+
"""
|
| 77 |
+
Creates multiple link emojis for a single entity.
|
| 78 |
+
Each link might point to /?q=..., /?q=<prefix>..., or external sites.
|
| 79 |
+
"""
|
| 80 |
+
search_urls = {
|
| 81 |
+
"🚀🌌ArXiv": lambda x: f"/?q={quote(x)}",
|
| 82 |
+
"🃏Analyst": lambda x: f"/?q={quote(x)}-{quote(PromptPrefix)}",
|
| 83 |
+
"📚PyCoder": lambda x: f"/?q={quote(x)}-{quote(PromptPrefix2)}",
|
| 84 |
+
"🔬JSCoder": lambda x: f"/?q={quote(x)}-{quote(PromptPrefix3)}",
|
| 85 |
+
"📖": lambda x: f"https://en.wikipedia.org/wiki/{quote(x)}",
|
| 86 |
+
"🔍": lambda x: f"https://www.google.com/search?q={quote(x)}",
|
| 87 |
+
"🔎": lambda x: f"https://www.bing.com/search?q={quote(x)}",
|
| 88 |
+
"🎥": lambda x: f"https://www.youtube.com/results?search_query={quote(x)}",
|
| 89 |
+
"🐦": lambda x: f"https://twitter.com/search?q={quote(x)}",
|
| 90 |
+
}
|
| 91 |
+
links_md = ' '.join([f"[{emoji}]({url(k)})" for emoji, url in search_urls.items()])
|
| 92 |
+
st.markdown(f"**{k}** <small>{links_md}</small>", unsafe_allow_html=True)
|
| 93 |
+
|
| 94 |
+
def display_content_or_image(query):
|
| 95 |
+
"""
|
| 96 |
+
If 'query' is in transhuman_glossary or there's an image matching 'images/<query>.png',
|
| 97 |
+
show it. Otherwise warn.
|
| 98 |
+
"""
|
| 99 |
+
for category, term_list in transhuman_glossary.items():
|
| 100 |
+
for term in term_list:
|
| 101 |
+
if query.lower() in term.lower():
|
| 102 |
+
st.subheader(f"Found in {category}:")
|
| 103 |
+
st.write(term)
|
| 104 |
+
return True
|
| 105 |
+
image_path = f"images/{query}.png"
|
| 106 |
+
if os.path.exists(image_path):
|
| 107 |
+
st.image(image_path, caption=f"Image for {query}")
|
| 108 |
+
return True
|
| 109 |
+
st.warning("No matching content or image found.")
|
| 110 |
+
return False
|
| 111 |
+
|
| 112 |
+
def clear_query_params():
|
| 113 |
+
"""Warn about clearing. Full clearing requires a redirect or st.experimental_set_query_params()."""
|
| 114 |
+
st.warning("Define a redirect or link without query params if you want to truly clear them.")
|
| 115 |
+
|
| 116 |
+
########################################################################################
|
| 117 |
+
# 3) FILE-HANDLING (MD files, etc.)
|
| 118 |
+
########################################################################################
|
| 119 |
+
def load_file(file_path):
|
| 120 |
+
"""Load file contents as UTF-8 text, or return empty on error."""
|
| 121 |
+
try:
|
| 122 |
+
with open(file_path, "r", encoding='utf-8') as f:
|
| 123 |
+
return f.read()
|
| 124 |
+
except:
|
| 125 |
+
return ""
|
| 126 |
+
|
| 127 |
+
@st.cache_resource
|
| 128 |
+
def create_zip_of_files(files):
|
| 129 |
+
"""Combine multiple local .md files into a single .zip for user to download."""
|
| 130 |
+
zip_name = "Arxiv-Paper-Search-QA-RAG-Streamlit-Gradio-AP.zip"
|
| 131 |
+
with zipfile.ZipFile(zip_name, 'w') as zipf:
|
| 132 |
+
for file in files:
|
| 133 |
+
zipf.write(file)
|
| 134 |
+
return zip_name
|
| 135 |
+
|
| 136 |
+
@st.cache_resource
|
| 137 |
+
def get_zip_download_link(zip_file):
|
| 138 |
+
"""Return an <a> link to download the given zip_file (base64-encoded)."""
|
| 139 |
+
with open(zip_file, 'rb') as f:
|
| 140 |
+
data = f.read()
|
| 141 |
+
b64 = base64.b64encode(data).decode()
|
| 142 |
+
return f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
| 143 |
+
|
| 144 |
+
def get_table_download_link(file_path):
|
| 145 |
+
"""
|
| 146 |
+
Creates a download link for a single file from your snippet.
|
| 147 |
+
Encodes it as base64 data.
|
| 148 |
+
"""
|
| 149 |
+
try:
|
| 150 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 151 |
+
data = file.read()
|
| 152 |
+
b64 = base64.b64encode(data.encode()).decode()
|
| 153 |
+
file_name = os.path.basename(file_path)
|
| 154 |
+
ext = os.path.splitext(file_name)[1]
|
| 155 |
+
mime_map = {
|
| 156 |
+
'.txt': 'text/plain',
|
| 157 |
+
'.py': 'text/plain',
|
| 158 |
+
'.xlsx': 'text/plain',
|
| 159 |
+
'.csv': 'text/plain',
|
| 160 |
+
'.htm': 'text/html',
|
| 161 |
+
'.md': 'text/markdown',
|
| 162 |
+
'.wav': 'audio/wav'
|
| 163 |
+
}
|
| 164 |
+
mime_type = mime_map.get(ext, 'application/octet-stream')
|
| 165 |
+
return f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
|
| 166 |
+
except:
|
| 167 |
+
return ''
|
| 168 |
+
|
| 169 |
+
def get_file_size(file_path):
|
| 170 |
+
"""Get file size in bytes."""
|
| 171 |
+
return os.path.getsize(file_path)
|
| 172 |
+
|
| 173 |
+
def FileSidebar():
|
| 174 |
+
"""
|
| 175 |
+
Renders .md files, providing open/view/delete/run logic in the sidebar.
|
| 176 |
+
"""
|
| 177 |
+
all_files = glob.glob("*.md")
|
| 178 |
+
# Exclude short-named or special files if needed:
|
| 179 |
+
all_files = [f for f in all_files if len(os.path.splitext(f)[0]) >= 5]
|
| 180 |
+
all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True)
|
| 181 |
+
|
| 182 |
+
Files1, Files2 = st.sidebar.columns(2)
|
| 183 |
+
with Files1:
|
| 184 |
+
if st.button("🗑 Delete All"):
|
| 185 |
+
for file in all_files:
|
| 186 |
+
os.remove(file)
|
| 187 |
+
st.rerun()
|
| 188 |
+
with Files2:
|
| 189 |
+
if st.button("⬇️ Download"):
|
| 190 |
+
zip_file = create_zip_of_files(all_files)
|
| 191 |
+
st.sidebar.markdown(get_zip_download_link(zip_file), unsafe_allow_html=True)
|
| 192 |
+
|
| 193 |
+
file_contents = ''
|
| 194 |
+
file_name = ''
|
| 195 |
+
next_action = ''
|
| 196 |
+
|
| 197 |
+
for file in all_files:
|
| 198 |
+
col1, col2, col3, col4, col5 = st.sidebar.columns([1,6,1,1,1])
|
| 199 |
+
with col1:
|
| 200 |
+
if st.button("🌐", key="md_"+file):
|
| 201 |
+
file_contents = load_file(file)
|
| 202 |
+
file_name = file
|
| 203 |
+
next_action = 'md'
|
| 204 |
+
st.session_state['next_action'] = next_action
|
| 205 |
+
with col2:
|
| 206 |
+
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
| 207 |
+
with col3:
|
| 208 |
+
if st.button("📂", key="open_"+file):
|
| 209 |
+
file_contents = load_file(file)
|
| 210 |
+
file_name = file
|
| 211 |
+
next_action = 'open'
|
| 212 |
+
st.session_state['lastfilename'] = file
|
| 213 |
+
st.session_state['filename'] = file
|
| 214 |
+
st.session_state['filetext'] = file_contents
|
| 215 |
+
st.session_state['next_action'] = next_action
|
| 216 |
+
with col4:
|
| 217 |
+
if st.button("▶️", key="read_"+file):
|
| 218 |
+
file_contents = load_file(file)
|
| 219 |
+
file_name = file
|
| 220 |
+
next_action = 'search'
|
| 221 |
+
st.session_state['next_action'] = next_action
|
| 222 |
+
with col5:
|
| 223 |
+
if st.button("🗑", key="delete_"+file):
|
| 224 |
+
os.remove(file)
|
| 225 |
+
st.rerun()
|
| 226 |
+
|
| 227 |
+
if file_contents:
|
| 228 |
+
if next_action == 'open':
|
| 229 |
+
open1, open2 = st.columns([0.8, 0.2])
|
| 230 |
+
with open1:
|
| 231 |
+
file_name_input = st.text_input('File Name:', file_name, key='file_name_input')
|
| 232 |
+
file_content_area = st.text_area('File Contents:', file_contents, height=300, key='file_content_area')
|
| 233 |
+
if st.button('💾 Save File'):
|
| 234 |
+
with open(file_name_input, 'w', encoding='utf-8') as f:
|
| 235 |
+
f.write(file_content_area)
|
| 236 |
+
st.markdown(f'Saved {file_name_input} successfully.')
|
| 237 |
+
elif next_action == 'search':
|
| 238 |
+
file_content_area = st.text_area("File Contents:", file_contents, height=500)
|
| 239 |
+
user_prompt = PromptPrefix2 + file_contents
|
| 240 |
+
st.markdown(user_prompt)
|
| 241 |
+
if st.button('🔍Re-Code'):
|
| 242 |
+
search_arxiv(file_contents)
|
| 243 |
+
elif next_action == 'md':
|
| 244 |
+
st.markdown(file_contents)
|
| 245 |
+
SpeechSynthesis(file_contents)
|
| 246 |
+
if st.button("🔍Run"):
|
| 247 |
+
st.write("Running GPT logic placeholder...")
|
| 248 |
+
|
| 249 |
+
########################################################################################
|
| 250 |
+
# 4) SCORING / GLOSSARIES
|
| 251 |
+
########################################################################################
|
| 252 |
+
score_dir = "scores"
|
| 253 |
+
os.makedirs(score_dir, exist_ok=True)
|
| 254 |
+
|
| 255 |
+
def generate_key(label, header, idx):
|
| 256 |
+
return f"{header}_{label}_{idx}_key"
|
| 257 |
+
|
| 258 |
+
def update_score(key, increment=1):
|
| 259 |
+
"""
|
| 260 |
+
Track a 'score' for each glossary item or term, saved in JSON per key.
|
| 261 |
+
"""
|
| 262 |
+
score_file = os.path.join(score_dir, f"{key}.json")
|
| 263 |
+
if os.path.exists(score_file):
|
| 264 |
+
with open(score_file, "r") as file:
|
| 265 |
+
score_data = json.load(file)
|
| 266 |
+
else:
|
| 267 |
+
score_data = {"clicks": 0, "score": 0}
|
| 268 |
+
score_data["clicks"] += increment
|
| 269 |
+
score_data["score"] += increment
|
| 270 |
+
with open(score_file, "w") as file:
|
| 271 |
+
json.dump(score_data, file)
|
| 272 |
+
return score_data["score"]
|
| 273 |
+
|
| 274 |
+
def load_score(key):
|
| 275 |
+
file_path = os.path.join(score_dir, f"{key}.json")
|
| 276 |
+
if os.path.exists(file_path):
|
| 277 |
+
with open(file_path, "r") as file:
|
| 278 |
+
score_data = json.load(file)
|
| 279 |
+
return score_data["score"]
|
| 280 |
+
return 0
|
| 281 |
+
|
| 282 |
+
def display_buttons_with_scores(num_columns_text):
|
| 283 |
+
"""
|
| 284 |
+
Show glossary items as clickable buttons that increment a 'score'.
|
| 285 |
+
"""
|
| 286 |
+
game_emojis = {
|
| 287 |
+
"Dungeons and Dragons": "🐉",
|
| 288 |
+
"Call of Cthulhu": "🐙",
|
| 289 |
+
"GURPS": "🎲",
|
| 290 |
+
"Pathfinder": "🗺️",
|
| 291 |
+
"Kindred of the East": "🌅",
|
| 292 |
+
"Changeling": "🍃",
|
| 293 |
+
}
|
| 294 |
+
topic_emojis = {
|
| 295 |
+
"Core Rulebooks": "📚",
|
| 296 |
+
"Maps & Settings": "🗺️",
|
| 297 |
+
"Game Mechanics & Tools": "⚙️",
|
| 298 |
+
"Monsters & Adversaries": "👹",
|
| 299 |
+
"Campaigns & Adventures": "📜",
|
| 300 |
+
"Creatives & Assets": "🎨",
|
| 301 |
+
"Game Master Resources": "🛠️",
|
| 302 |
+
"Lore & Background": "📖",
|
| 303 |
+
"Character Development": "🧍",
|
| 304 |
+
"Homebrew Content": "🔧",
|
| 305 |
+
"General Topics": "🌍",
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
for category, games in roleplaying_glossary.items():
|
| 309 |
+
category_emoji = topic_emojis.get(category, "🔍")
|
| 310 |
+
st.markdown(f"## {category_emoji} {category}")
|
| 311 |
+
for game, terms in games.items():
|
| 312 |
+
game_emoji = game_emojis.get(game, "🎮")
|
| 313 |
+
for term in terms:
|
| 314 |
+
key = f"{category}_{game}_{term}".replace(' ', '_').lower()
|
| 315 |
+
score_val = load_score(key)
|
| 316 |
+
if st.button(f"{game_emoji} {category} {game} {term} {score_val}", key=key):
|
| 317 |
+
newscore = update_score(key.replace('?', ''))
|
| 318 |
+
st.markdown(f"Scored **{category} - {game} - {term}** -> {newscore}")
|
| 319 |
+
|
| 320 |
+
########################################################################################
|
| 321 |
+
# 5) IMAGES & VIDEOS
|
| 322 |
+
########################################################################################
|
| 323 |
+
|
| 324 |
+
def display_images_and_wikipedia_summaries(num_columns=4):
|
| 325 |
+
"""Display .png images in a grid, referencing the name as a 'keyword'."""
|
| 326 |
+
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
| 327 |
+
if not image_files:
|
| 328 |
+
st.write("No PNG images found in the current directory.")
|
| 329 |
+
return
|
| 330 |
+
|
| 331 |
+
image_files_sorted = sorted(image_files, key=lambda x: len(x.split('.')[0]))
|
| 332 |
+
cols = st.columns(num_columns)
|
| 333 |
+
col_index = 0
|
| 334 |
+
for image_file in image_files_sorted:
|
| 335 |
+
with cols[col_index % num_columns]:
|
| 336 |
+
try:
|
| 337 |
+
image = Image.open(image_file)
|
| 338 |
+
st.image(image, use_column_width=True)
|
| 339 |
+
k = image_file.split('.')[0]
|
| 340 |
+
display_glossary_entity(k)
|
| 341 |
+
image_text_input = st.text_input(f"Prompt for {image_file}", key=f"image_prompt_{image_file}")
|
| 342 |
+
if image_text_input:
|
| 343 |
+
response = process_image(image_file, image_text_input)
|
| 344 |
+
st.markdown(response)
|
| 345 |
+
except:
|
| 346 |
+
st.write(f"Could not open {image_file}")
|
| 347 |
+
col_index += 1
|
| 348 |
+
|
| 349 |
+
def display_videos_and_links(num_columns=4):
|
| 350 |
+
"""Displays all .mp4/.webm in a grid, plus text input for prompts."""
|
| 351 |
+
video_files = [f for f in os.listdir('.') if f.endswith(('.mp4', '.webm'))]
|
| 352 |
+
if not video_files:
|
| 353 |
+
st.write("No MP4 or WEBM videos found in the current directory.")
|
| 354 |
+
return
|
| 355 |
+
|
| 356 |
+
video_files_sorted = sorted(video_files, key=lambda x: len(x.split('.')[0]))
|
| 357 |
+
cols = st.columns(num_columns)
|
| 358 |
+
col_index = 0
|
| 359 |
+
for video_file in video_files_sorted:
|
| 360 |
+
with cols[col_index % num_columns]:
|
| 361 |
+
k = video_file.split('.')[0]
|
| 362 |
+
st.video(video_file, format='video/mp4', start_time=0)
|
| 363 |
+
display_glossary_entity(k)
|
| 364 |
+
video_text_input = st.text_input(f"Video Prompt for {video_file}", key=f"video_prompt_{video_file}")
|
| 365 |
+
if video_text_input:
|
| 366 |
+
try:
|
| 367 |
+
seconds_per_frame = 10
|
| 368 |
+
process_video(video_file, seconds_per_frame)
|
| 369 |
+
except ValueError:
|
| 370 |
+
st.error("Invalid input for seconds per frame!")
|
| 371 |
+
col_index += 1
|
| 372 |
+
|
| 373 |
+
########################################################################################
|
| 374 |
+
# 6) MERMAID
|
| 375 |
+
########################################################################################
|
| 376 |
+
|
| 377 |
+
def generate_mermaid_html(mermaid_code: str) -> str:
|
| 378 |
+
"""
|
| 379 |
+
Returns HTML that centers the Mermaid diagram, loading from a CDN.
|
| 380 |
+
"""
|
| 381 |
+
return f"""
|
| 382 |
+
<html>
|
| 383 |
+
<head>
|
| 384 |
+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
| 385 |
+
<style>
|
| 386 |
+
.centered-mermaid {{
|
| 387 |
+
display: flex;
|
| 388 |
+
justify-content: center;
|
| 389 |
+
margin: 20px auto;
|
| 390 |
+
}}
|
| 391 |
+
.mermaid {{
|
| 392 |
+
max-width: 800px;
|
| 393 |
+
}}
|
| 394 |
+
</style>
|
| 395 |
+
</head>
|
| 396 |
+
<body>
|
| 397 |
+
<div class="mermaid centered-mermaid">
|
| 398 |
+
{mermaid_code}
|
| 399 |
+
</div>
|
| 400 |
+
<script>
|
| 401 |
+
mermaid.initialize({{ startOnLoad: true }});
|
| 402 |
+
</script>
|
| 403 |
+
</body>
|
| 404 |
+
</html>
|
| 405 |
+
"""
|
| 406 |
+
|
| 407 |
+
def append_model_param(url: str, model_selected: bool) -> str:
|
| 408 |
+
"""
|
| 409 |
+
If user checks 'Append ?model=1', we append &model=1 or ?model=1 if not present.
|
| 410 |
+
"""
|
| 411 |
+
if not model_selected:
|
| 412 |
+
return url
|
| 413 |
+
delimiter = "&" if "?" in url else "?"
|
| 414 |
+
return f"{url}{delimiter}model=1"
|
| 415 |
+
|
| 416 |
+
def inject_base_url(url: str) -> str:
|
| 417 |
+
"""
|
| 418 |
+
If a link does not start with http, prepend your BASE_URL
|
| 419 |
+
so it becomes an absolute link to huggingface.co/spaces/...
|
| 420 |
+
"""
|
| 421 |
+
if url.startswith("http"):
|
| 422 |
+
return url
|
| 423 |
+
return f"{BASE_URL}{url}"
|
| 424 |
+
|
| 425 |
+
# We use 2-parameter click lines for Mermaid 11.4.1 compatibility:
|
| 426 |
+
DEFAULT_MERMAID = r"""
|
| 427 |
+
flowchart LR
|
| 428 |
+
U((User 😎)) -- "Talk 🗣️" --> LLM[LLM Agent 🤖\nExtract Info]
|
| 429 |
+
click U "?q=U" _self
|
| 430 |
+
click LLM "?q=LLM%20Agent%20Extract%20Info" _blank
|
| 431 |
+
|
| 432 |
+
LLM -- "Query 🔍" --> HS[Hybrid Search 🔎\nVector+NER+Lexical]
|
| 433 |
+
click HS "?q=Hybrid%20Search%20Vector%20NER%20Lexical" _blank
|
| 434 |
+
|
| 435 |
+
HS -- "Reason 🤔" --> RE[Reasoning Engine 🛠️\nNeuralNetwork+Medical]
|
| 436 |
+
click RE "?q=R" _blank
|
| 437 |
+
|
| 438 |
+
RE -- "Link 📡" --> KG((Knowledge Graph 📚\nOntology+GAR+RAG))
|
| 439 |
+
click KG "?q=K" _blank
|
| 440 |
+
"""
|
| 441 |
+
|
| 442 |
+
# New function to generate Mermaid diagram for each paper
|
| 443 |
+
def generate_mermaid_code(paper):
|
| 444 |
+
title = paper.split('|')[1].strip()
|
| 445 |
+
concepts = paper.split('\n')
|
| 446 |
+
mermaid_code = f"flowchart TD\n A[{title}]"
|
| 447 |
+
for concept in concepts[1:]: # Skip the title
|
| 448 |
+
if concept.strip():
|
| 449 |
+
mermaid_code += f" --> {concept.strip().replace('*', '').replace(',', '').replace(' ', '')}"
|
| 450 |
+
return mermaid_code
|
| 451 |
+
|
| 452 |
+
########################################################################################
|
| 453 |
+
# 7) MAIN UI
|
| 454 |
+
########################################################################################
|
| 455 |
+
|
| 456 |
+
def main():
|
| 457 |
+
st.set_page_config(page_title="Mermaid + Two-Parameter Click + LetterMap", layout="wide")
|
| 458 |
+
|
| 459 |
+
# Define a list of 10 slides (each with left and right pages), built from 40 paper entries.
|
| 460 |
+
slides = [
|
| 461 |
+
{
|
| 462 |
+
"left": """
|
| 463 |
+
### 07 Sep 2023 | [Structured Chain-of-Thought Prompting for Code Generation](https://arxiv.org/abs/2305.06599) | [⬇️](https://arxiv.org/pdf/2305.06599)
|
| 464 |
+
*Jia Li, Ge Li, Yongmin Li, Zhi Jin*
|
| 465 |
+
|
| 466 |
+
### 15 Nov 2023 | [Eliminating Reasoning via Inferring with Planning: A New Framework to Guide LLMs' Non-linear Thinking](https://arxiv.org/abs/2310.12342) | [⬇️](https://arxiv.org/pdf/2310.12342)
|
| 467 |
+
*Yongqi Tong, Yifan Wang, Dawei Li, Sizhe Wang, Zi Lin, Simeng Han, Jingbo Shang*
|
| 468 |
+
""",
|
| 469 |
+
"right": """
|
| 470 |
+
### 04 Jun 2023 | [Evaluating and Improving Tool-Augmented Computation-Intensive Math Reasoning](https://arxiv.org/abs/2306.02408) | [⬇️](https://arxiv.org/pdf/2306.02408)
|
| 471 |
+
*Beichen Zhang, Kun Zhou, Xilin Wei, Wayne Xin Zhao, Jing Sha, Shijin Wang, Ji-Rong Wen*
|
| 472 |
+
|
| 473 |
+
### 23 Oct 2023 | [Program of Thoughts Prompting: Disentangling Computation from Reasoning for Numerical Reasoning Tasks](https://arxiv.org/abs/2211.12588) | [⬇️](https://arxiv.org/pdf/2211.12588)
|
| 474 |
+
*Wenhu Chen, Xueguang Ma, Xinyi Wang, William W. Cohen*
|
| 475 |
+
"""
|
| 476 |
+
},
|
| 477 |
+
{
|
| 478 |
+
"left": """
|
| 479 |
+
### 04 Jan 2024 | [Text2MDT: Extracting Medical Decision Trees from Medical Texts](https://arxiv.org/abs/2401.02034) | [⬇️](https://arxiv.org/pdf/2401.02034)
|
| 480 |
+
*Wei Zhu, Wenfeng Li, Xing Tian, Pengfei Wang, Xiaoling Wang, Jin Chen, Yuanbin Wu, Yuan Ni, Guotong Xie*
|
| 481 |
+
|
| 482 |
+
### 21 Dec 2023 | [Automating Human Tutor-Style Programming Feedback: Leveraging GPT-4 Tutor Model for Hint Generation and GPT-3.5 Student Model for Hint Validation](https://arxiv.org/abs/2310.03780) | [⬇️](https://arxiv.org/pdf/2310.03780)
|
| 483 |
+
*Tung Phung, Victor-Alexandru Pădurean, Anjali Singh, Christopher Brooks, José Cambronero, Sumit Gulwani, Adish Singla, Gustavo Soares*
|
| 484 |
+
""",
|
| 485 |
+
"right": """
|
| 486 |
+
### 04 Feb 2024 | [STEVE-1: A Generative Model for Text-to-Behavior in Minecraft](https://arxiv.org/abs/2306.00937) | [⬇️](https://arxiv.org/pdf/2306.00937)
|
| 487 |
+
*Shalev Lifshitz, Keiran Paster, Harris Chan, Jimmy Ba, Sheila McIlraith*
|
| 488 |
+
|
| 489 |
+
### 20 May 2021 | [Data-Efficient Reinforcement Learning with Self-Predictive Representations](https://arxiv.org/abs/2007.05929) | [⬇️](https://arxiv.org/pdf/2007.05929)
|
| 490 |
+
*Max Schwarzer, Ankesh Anand, Rishab Goel, R Devon Hjelm, Aaron Courville, Philip Bachman*
|
| 491 |
+
"""
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"left": """
|
| 495 |
+
### 06 Jul 2022 | [Learning Invariant World State Representations with Predictive Coding](https://arxiv.org/abs/2207.02972) | [⬇️](https://arxiv.org/pdf/2207.02972)
|
| 496 |
+
*Avi Ziskind, Sujeong Kim, and Giedrius T. Burachas*
|
| 497 |
+
|
| 498 |
+
### 10 Nov 2023 | [State2Explanation: Concept-Based Explanations to Benefit Agent Learning and User Understanding](https://arxiv.org/abs/2309.12482) | [⬇️](https://arxiv.org/pdf/2309.12482)
|
| 499 |
+
*Devleena Das, Sonia Chernova, Been Kim*
|
| 500 |
+
""",
|
| 501 |
+
"right": """
|
| 502 |
+
### 17 May 2023 | [LeTI: Learning to Generate from Textual Interactions](https://arxiv.org/abs/2305.10314) | [⬇️](https://arxiv.org/pdf/2305.10314)
|
| 503 |
+
*Xingyao Wang, Hao Peng, Reyhaneh Jabbarvand, Heng Ji*
|
| 504 |
+
|
| 505 |
+
### 01 Dec 2022 | [A General Purpose Supervisory Signal for Embodied Agents](https://arxiv.org/abs/2212.01186) | [⬇️](https://arxiv.org/pdf/2212.01186)
|
| 506 |
+
*Kunal Pratap Singh, Jordi Salvador, Luca Weihs, Aniruddha Kembhavi*
|
| 507 |
+
"""
|
| 508 |
+
},
|
| 509 |
+
{
|
| 510 |
+
"left": """
|
| 511 |
+
### 16 May 2023 | [RAMario: Experimental Approach to Reptile Algorithm -- Reinforcement Learning for Mario](https://arxiv.org/abs/2305.09655) | [⬇️](https://arxiv.org/pdf/2305.09655)
|
| 512 |
+
*Sanyam Jain*
|
| 513 |
+
|
| 514 |
+
### 31 Mar 2023 | [Pair Programming with Large Language Models for Sampling and Estimation of Copulas](https://arxiv.org/abs/2303.18116) | [⬇️](https://arxiv.org/pdf/2303.18116)
|
| 515 |
+
*Jan Górecki*
|
| 516 |
+
""",
|
| 517 |
+
"right": """
|
| 518 |
+
### 28 Jun 2023 | [AssistGPT: A General Multi-modal Assistant that can Plan, Execute, Inspect, and Learn](https://arxiv.org/abs/2306.08640) | [⬇️](https://arxiv.org/pdf/2306.08640)
|
| 519 |
+
*Difei Gao, Lei Ji, Luowei Zhou, Kevin Qinghong Lin, Joya Chen, Zihan Fan, Mike Zheng Shou*
|
| 520 |
+
|
| 521 |
+
### 07 Nov 2023 | [Selective Visual Representations Improve Convergence and Generalization for Embodied AI](https://arxiv.org/abs/2311.04193) | [⬇️](https://arxiv.org/pdf/2311.04193)
|
| 522 |
+
*Ainaz Eftekhar, Kuo-Hao Zeng, Jiafei Duan, Ali Farhadi, Ani Kembhavi, Ranjay Krishna*
|
| 523 |
+
"""
|
| 524 |
+
},
|
| 525 |
+
{
|
| 526 |
+
"left": """
|
| 527 |
+
### 16 Feb 2023 | [Foundation Models for Natural Language Processing -- Pre-trained Language Models Integrating Media](https://arxiv.org/abs/2302.08575) | [⬇️](https://arxiv.org/pdf/2302.08575)
|
| 528 |
+
*Gerhard Paaß and Sven Giesselbach*
|
| 529 |
+
|
| 530 |
+
### 21 Dec 2023 | [Automating Human Tutor-Style Programming Feedback: Leveraging GPT-4 Tutor Model for Hint Generation and GPT-3.5 Student Model for Hint Validation](https://arxiv.org/abs/2310.03780) | [⬇️](https://arxiv.org/pdf/2310.03780)
|
| 531 |
+
*Tung Phung, Victor-Alexandru Pădurean, Anjali Singh, Christopher Brooks, José Cambronero, Sumit Gulwani, Adish Singla, Gustavo Soares*
|
| 532 |
+
""",
|
| 533 |
+
"right": """
|
| 534 |
+
### 04 Feb 2024 | [STEVE-1: A Generative Model for Text-to-Behavior in Minecraft](https://arxiv.org/abs/2306.00937) | [⬇️](https://arxiv.org/pdf/2306.00937)
|
| 535 |
+
*Shalev Lifshitz, Keiran Paster, Harris Chan, Jimmy Ba, Sheila McIlraith*
|
| 536 |
+
|
| 537 |
+
### 20 May 2021 | [Data-Efficient Reinforcement Learning with Self-Predictive Representations](https://arxiv.org/abs/2007.05929) | [⬇️](https://arxiv.org/pdf/2007.05929)
|
| 538 |
+
*Max Schwarzer, Ankesh Anand, Rishab Goel, R Devon Hjelm, Aaron Courville, Philip Bachman*
|
| 539 |
+
"""
|
| 540 |
+
},
|
| 541 |
+
{
|
| 542 |
+
"left": """
|
| 543 |
+
### 06 Jul 2022 | [Learning Invariant World State Representations with Predictive Coding](https://arxiv.org/abs/2207.02972) | [⬇️](https://arxiv.org/pdf/2207.02972)
|
| 544 |
+
*Avi Ziskind, Sujeong Kim, and Giedrius T. Burachas*
|
| 545 |
+
|
| 546 |
+
### 10 Nov 2023 | [State2Explanation: Concept-Based Explanations to Benefit Agent Learning and User Understanding](https://arxiv.org/abs/2309.12482) | [⬇️](https://arxiv.org/pdf/2309.12482)
|
| 547 |
+
*Devleena Das, Sonia Chernova, Been Kim*
|
| 548 |
+
""",
|
| 549 |
+
"right": """
|
| 550 |
+
### 17 May 2023 | [LeTI: Learning to Generate from Textual Interactions](https://arxiv.org/abs/2305.10314) | [⬇️](https://arxiv.org/pdf/2305.10314)
|
| 551 |
+
*Xingyao Wang, Hao Peng, Reyhaneh Jabbarvand, Heng Ji*
|
| 552 |
+
|
| 553 |
+
### 01 Dec 2022 | [A General Purpose Supervisory Signal for Embodied Agents](https://arxiv.org/abs/2212.01186) | [⬇️](https://arxiv.org/pdf/2212.01186)
|
| 554 |
+
*Kunal Pratap Singh, Jordi Salvador, Luca Weihs, Aniruddha Kembhavi*
|
| 555 |
+
"""
|
| 556 |
+
},
|
| 557 |
+
{
|
| 558 |
+
"left": """
|
| 559 |
+
### 16 May 2023 | [RAMario: Experimental Approach to Reptile Algorithm -- Reinforcement Learning for Mario](https://arxiv.org/abs/2305.09655) | [⬇️](https://arxiv.org/pdf/2305.09655)
|
| 560 |
+
*Sanyam Jain*
|
| 561 |
+
|
| 562 |
+
### 31 Mar 2023 | [Pair Programming with Large Language Models for Sampling and Estimation of Copulas](https://arxiv.org/abs/2303.18116) | [⬇️](https://arxiv.org/pdf/2303.18116)
|
| 563 |
+
*Jan Górecki*
|
| 564 |
+
""",
|
| 565 |
+
"right": """
|
| 566 |
+
### 28 Jun 2023 | [AssistGPT: A General Multi-modal Assistant that can Plan, Execute, Inspect, and Learn](https://arxiv.org/abs/2306.08640) | [⬇️](https://arxiv.org/pdf/2306.08640)
|
| 567 |
+
*Difei Gao, Lei Ji, Luowei Zhou, Kevin Qinghong Lin, Joya Chen, Zihan Fan, Mike Zheng Shou*
|
| 568 |
+
|
| 569 |
+
### 07 Nov 2023 | [Selective Visual Representations Improve Convergence and Generalization for Embodied AI](https://arxiv.org/abs/2311.04193) | [⬇️](https://arxiv.org/pdf/2311.04193)
|
| 570 |
+
*Ainaz Eftekhar, Kuo-Hao Zeng, Jiafei Duan, Ali Farhadi, Ani Kembhavi, Ranjay Krishna*
|
| 571 |
+
"""
|
| 572 |
+
},
|
| 573 |
+
{
|
| 574 |
+
"left": """
|
| 575 |
+
### 16 Feb 2023 | [Foundation Models for Natural Language Processing -- Pre-trained Language Models Integrating Media](https://arxiv.org/abs/2302.08575) | [⬇️](https://arxiv.org/pdf/2302.08575)
|
| 576 |
+
*Gerhard Paaß and Sven Giesselbach*
|
| 577 |
+
|
| 578 |
+
### 21 Dec 2023 | [Automating Human Tutor-Style Programming Feedback: Leveraging GPT-4 Tutor Model for Hint Generation and GPT-3.5 Student Model for Hint Validation](https://arxiv.org/abs/2310.03780) | [⬇️](https://arxiv.org/pdf/2310.03780)
|
| 579 |
+
*Tung Phung, Victor-Alexandru Pădurean, Anjali Singh, Christopher Brooks, José Cambronero, Sumit Gulwani, Adish Singla, Gustavo Soares*
|
| 580 |
+
""",
|
| 581 |
+
"right": """
|
| 582 |
+
### 04 Feb 2024 | [STEVE-1: A Generative Model for Text-to-Behavior in Minecraft](https://arxiv.org/abs/2306.00937) | [⬇️](https://arxiv.org/pdf/2306.00937)
|
| 583 |
+
*Shalev Lifshitz, Keiran Paster, Harris Chan, Jimmy Ba, Sheila McIlraith*
|
| 584 |
+
|
| 585 |
+
### 20 May 2021 | [Data-Efficient Reinforcement Learning with Self-Predictive Representations](https://arxiv.org/abs/2007.05929) | [⬇️](https://arxiv.org/pdf/2007.05929)
|
| 586 |
+
*Max Schwarzer, Ankesh Anand, Rishab Goel, R Devon Hjelm, Aaron Courville, Philip Bachman*
|
| 587 |
+
"""
|
| 588 |
+
}
|
| 589 |
+
]
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
|
| 595 |
+
# Initialize slide index in session state if not already set
|
| 596 |
+
if "slide_idx" not in st.session_state:
|
| 597 |
+
st.session_state.slide_idx = 0
|
| 598 |
+
|
| 599 |
+
num_slides = len(slides)
|
| 600 |
+
current_slide = slides[st.session_state.slide_idx]
|
| 601 |
+
|
| 602 |
+
# Display slide header (e.g., "Slide 1 of 10")
|
| 603 |
+
st.markdown(f"## Slide {st.session_state.slide_idx + 1} of {num_slides}")
|
| 604 |
+
|
| 605 |
+
# Display left and right pages side by side
|
| 606 |
+
col_left, col_right = st.columns(2)
|
| 607 |
+
with col_left:
|
| 608 |
+
st.markdown("### Left Page")
|
| 609 |
+
for paper in current_slide["left"].split('\n\n'):
|
| 610 |
+
if paper.strip():
|
| 611 |
+
st.markdown(paper, unsafe_allow_html=True)
|
| 612 |
+
mermaid_diagram = generate_mermaid_code(paper)
|
| 613 |
+
st.markdown(f"```mermaid\n{mermaid_diagram}\n```", unsafe_allow_html=True)
|
| 614 |
+
with col_right:
|
| 615 |
+
st.markdown("### Right Page")
|
| 616 |
+
for paper in current_slide["right"].split('\n\n'):
|
| 617 |
+
if paper.strip():
|
| 618 |
+
st.markdown(paper, unsafe_allow_html=True)
|
| 619 |
+
mermaid_diagram = generate_mermaid_code(paper)
|
| 620 |
+
st.markdown(f"```mermaid\n{mermaid_diagram}\n```", unsafe_allow_html=True)
|
| 621 |
+
|
| 622 |
+
# Countdown timer (15 seconds) for auto-advancement
|
| 623 |
+
for remaining in range(15, 0, -1):
|
| 624 |
+
st.markdown(f"**Advancing in {remaining} seconds...**")
|
| 625 |
+
time.sleep(1)
|
| 626 |
+
|
| 627 |
+
# Advance to the next slide (wrap around at the end)
|
| 628 |
+
st.session_state.slide_idx = (st.session_state.slide_idx + 1) % num_slides
|
| 629 |
+
|
| 630 |
+
# Rerun the app to display the next slide
|
| 631 |
+
st.rerun()
|
| 632 |
+
|
| 633 |
+
if __name__ == "__main__":
|
| 634 |
+
main()
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
|
| 639 |
+
|
| 640 |
+
|