Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,6 +82,13 @@ Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """
|
|
| 82 |
29. Valheim
|
| 83 |
"""
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
def sanitize_filename(text):
|
| 86 |
"""Create a safe filename from text while preserving spaces."""
|
| 87 |
# First replace unsafe characters with spaces
|
|
@@ -136,14 +143,13 @@ def get_file_download_link(file_path):
|
|
| 136 |
with open(file_path, 'r', encoding='utf-8') as f:
|
| 137 |
content = f.read()
|
| 138 |
b64 = base64.b64encode(content.encode()).decode()
|
| 139 |
-
|
| 140 |
-
return f'<a href="data:text/markdown;base64,{b64}" download="{filename}">{filename}</a>'
|
| 141 |
except Exception as e:
|
| 142 |
st.error(f"Error creating download link: {e}")
|
| 143 |
return None
|
| 144 |
|
| 145 |
-
# Function to parse markdown text and extract terms
|
| 146 |
def extract_terms(markdown_text):
|
|
|
|
| 147 |
lines = markdown_text.strip().split('\n')
|
| 148 |
terms = []
|
| 149 |
for line in lines:
|
|
@@ -152,8 +158,8 @@ def extract_terms(markdown_text):
|
|
| 152 |
terms.append(line)
|
| 153 |
return terms
|
| 154 |
|
| 155 |
-
# Function to display terms with links
|
| 156 |
def display_terms_with_links(terms):
|
|
|
|
| 157 |
search_urls = {
|
| 158 |
"๐๐ArXiv": lambda k: f"/?q={quote(k)}",
|
| 159 |
"๐": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
|
@@ -166,8 +172,8 @@ def display_terms_with_links(terms):
|
|
| 166 |
links_md = ' '.join([f"[{emoji}]({url(term)})" for emoji, url in search_urls.items()])
|
| 167 |
st.markdown(f"- **{term}** {links_md}", unsafe_allow_html=True)
|
| 168 |
|
| 169 |
-
# Function to perform AI lookup using Gradio client
|
| 170 |
def perform_ai_lookup(query):
|
|
|
|
| 171 |
st.write("Performing AI Lookup...")
|
| 172 |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
| 173 |
result1 = client.predict(
|
|
@@ -217,55 +223,82 @@ def display_file_content(file_path):
|
|
| 217 |
st.error(f"Error reading file: {e}")
|
| 218 |
|
| 219 |
def file_management_sidebar():
|
| 220 |
-
"""
|
| 221 |
st.sidebar.title("๐ File Management")
|
| 222 |
|
| 223 |
-
# Get list of .md files
|
| 224 |
-
md_files =
|
|
|
|
| 225 |
st.session_state.files = md_files
|
| 226 |
|
| 227 |
if md_files:
|
| 228 |
-
st.sidebar.markdown("###
|
| 229 |
for idx, file in enumerate(md_files):
|
| 230 |
-
|
| 231 |
|
| 232 |
-
|
| 233 |
-
|
| 234 |
|
| 235 |
-
with
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
| 242 |
st.session_state.selected_file = file
|
| 243 |
st.session_state.view_mode = 'view'
|
| 244 |
|
| 245 |
-
with
|
| 246 |
-
|
| 247 |
-
if st.button("โ๏ธ", key=f"edit_{idx}"):
|
| 248 |
st.session_state.selected_file = file
|
| 249 |
st.session_state.view_mode = 'edit'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
|
|
|
| 251 |
# Option to create a new markdown file
|
| 252 |
-
if st.sidebar.button("Create New
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
with open(new_filename, 'w', encoding='utf-8') as f:
|
| 256 |
f.write("# New Markdown File\n")
|
| 257 |
-
st.sidebar.success(f"Created
|
| 258 |
-
st.session_state.selected_file =
|
| 259 |
st.session_state.view_mode = 'edit'
|
| 260 |
else:
|
| 261 |
st.sidebar.write("No markdown files found.")
|
| 262 |
-
if st.sidebar.button("Create
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
with open(new_filename, 'w', encoding='utf-8') as f:
|
| 266 |
f.write("# New Markdown File\n")
|
| 267 |
-
st.sidebar.success(f"Created
|
| 268 |
-
st.session_state.selected_file =
|
| 269 |
st.session_state.view_mode = 'edit'
|
| 270 |
|
| 271 |
def main():
|
|
|
|
| 82 |
29. Valheim
|
| 83 |
"""
|
| 84 |
|
| 85 |
+
def get_display_name(filename):
|
| 86 |
+
"""Extract text from parentheses or return filename as is."""
|
| 87 |
+
match = re.search(r'\((.*?)\)', filename)
|
| 88 |
+
if match:
|
| 89 |
+
return match.group(1)
|
| 90 |
+
return filename
|
| 91 |
+
|
| 92 |
def sanitize_filename(text):
|
| 93 |
"""Create a safe filename from text while preserving spaces."""
|
| 94 |
# First replace unsafe characters with spaces
|
|
|
|
| 143 |
with open(file_path, 'r', encoding='utf-8') as f:
|
| 144 |
content = f.read()
|
| 145 |
b64 = base64.b64encode(content.encode()).decode()
|
| 146 |
+
return f"data:text/markdown;base64,{b64}"
|
|
|
|
| 147 |
except Exception as e:
|
| 148 |
st.error(f"Error creating download link: {e}")
|
| 149 |
return None
|
| 150 |
|
|
|
|
| 151 |
def extract_terms(markdown_text):
|
| 152 |
+
"""Parse markdown text and extract terms."""
|
| 153 |
lines = markdown_text.strip().split('\n')
|
| 154 |
terms = []
|
| 155 |
for line in lines:
|
|
|
|
| 158 |
terms.append(line)
|
| 159 |
return terms
|
| 160 |
|
|
|
|
| 161 |
def display_terms_with_links(terms):
|
| 162 |
+
"""Display terms with various search links."""
|
| 163 |
search_urls = {
|
| 164 |
"๐๐ArXiv": lambda k: f"/?q={quote(k)}",
|
| 165 |
"๐": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
|
|
|
| 172 |
links_md = ' '.join([f"[{emoji}]({url(term)})" for emoji, url in search_urls.items()])
|
| 173 |
st.markdown(f"- **{term}** {links_md}", unsafe_allow_html=True)
|
| 174 |
|
|
|
|
| 175 |
def perform_ai_lookup(query):
|
| 176 |
+
"""Perform AI lookup using Gradio client."""
|
| 177 |
st.write("Performing AI Lookup...")
|
| 178 |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
| 179 |
result1 = client.predict(
|
|
|
|
| 223 |
st.error(f"Error reading file: {e}")
|
| 224 |
|
| 225 |
def file_management_sidebar():
|
| 226 |
+
"""Redesigned sidebar with improved layout and additional functionality."""
|
| 227 |
st.sidebar.title("๐ File Management")
|
| 228 |
|
| 229 |
+
# Get list of .md files excluding README.md
|
| 230 |
+
md_files = [file for file in glob.glob("*.md") if file.lower() != 'readme.md']
|
| 231 |
+
md_files.sort()
|
| 232 |
st.session_state.files = md_files
|
| 233 |
|
| 234 |
if md_files:
|
| 235 |
+
st.sidebar.markdown("### Saved Files")
|
| 236 |
for idx, file in enumerate(md_files):
|
| 237 |
+
st.sidebar.markdown("---") # Separator between files
|
| 238 |
|
| 239 |
+
# Display filename
|
| 240 |
+
st.sidebar.text(file)
|
| 241 |
|
| 242 |
+
# Display download link with simplified text
|
| 243 |
+
display_name = get_display_name(file)
|
| 244 |
+
download_link = get_file_download_link(file)
|
| 245 |
+
if download_link:
|
| 246 |
+
st.sidebar.markdown(f"๐ฅ [{display_name}]({download_link})", unsafe_allow_html=True)
|
| 247 |
|
| 248 |
+
# Action buttons in a row
|
| 249 |
+
col1, col2, col3 = st.sidebar.columns(3)
|
| 250 |
+
|
| 251 |
+
with col1:
|
| 252 |
+
if st.button("๐ View", key=f"view_{idx}"):
|
| 253 |
st.session_state.selected_file = file
|
| 254 |
st.session_state.view_mode = 'view'
|
| 255 |
|
| 256 |
+
with col2:
|
| 257 |
+
if st.button("โ๏ธ Edit", key=f"edit_{idx}"):
|
|
|
|
| 258 |
st.session_state.selected_file = file
|
| 259 |
st.session_state.view_mode = 'edit'
|
| 260 |
+
|
| 261 |
+
with col3:
|
| 262 |
+
if st.button("๐ Rerun", key=f"rerun_{idx}"):
|
| 263 |
+
try:
|
| 264 |
+
with open(file, 'r', encoding='utf-8') as f:
|
| 265 |
+
content = f.read()
|
| 266 |
+
|
| 267 |
+
# Prepare the prompt with the prefix
|
| 268 |
+
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:
|
| 269 |
+
|
| 270 |
+
"""
|
| 271 |
+
full_prompt = rerun_prefix + content
|
| 272 |
+
|
| 273 |
+
# Perform AI lookup and save results
|
| 274 |
+
ai_result = perform_ai_lookup(full_prompt)
|
| 275 |
+
saved_file = save_ai_interaction(f"Rerun of {file}", ai_result)
|
| 276 |
+
|
| 277 |
+
if saved_file:
|
| 278 |
+
st.success(f"Created fun version in {saved_file}")
|
| 279 |
+
st.session_state.selected_file = saved_file
|
| 280 |
+
st.session_state.view_mode = 'view'
|
| 281 |
+
|
| 282 |
+
except Exception as e:
|
| 283 |
+
st.error(f"Error during rerun: {e}")
|
| 284 |
|
| 285 |
+
st.sidebar.markdown("---")
|
| 286 |
# Option to create a new markdown file
|
| 287 |
+
if st.sidebar.button("๐ Create New Note"):
|
| 288 |
+
filename = generate_timestamp_filename("New Note")
|
| 289 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
|
|
|
| 290 |
f.write("# New Markdown File\n")
|
| 291 |
+
st.sidebar.success(f"Created: {filename}")
|
| 292 |
+
st.session_state.selected_file = filename
|
| 293 |
st.session_state.view_mode = 'edit'
|
| 294 |
else:
|
| 295 |
st.sidebar.write("No markdown files found.")
|
| 296 |
+
if st.sidebar.button("๐ Create First Note"):
|
| 297 |
+
filename = generate_timestamp_filename("New Note")
|
| 298 |
+
with open(filename, 'w', encoding='utf-8') as f:
|
|
|
|
| 299 |
f.write("# New Markdown File\n")
|
| 300 |
+
st.sidebar.success(f"Created: {filename}")
|
| 301 |
+
st.session_state.selected_file = filename
|
| 302 |
st.session_state.view_mode = 'edit'
|
| 303 |
|
| 304 |
def main():
|