Spaces:
Running
Running
Update backup4.QuerryParamsFixed..app.py
Browse files
backup4.QuerryParamsFixed..app.py
CHANGED
|
@@ -3,6 +3,7 @@ import os
|
|
| 3 |
import glob
|
| 4 |
import re
|
| 5 |
import base64
|
|
|
|
| 6 |
from urllib.parse import quote
|
| 7 |
from gradio_client import Client
|
| 8 |
from datetime import datetime
|
|
@@ -82,23 +83,39 @@ Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """
|
|
| 82 |
"""
|
| 83 |
|
| 84 |
def sanitize_filename(text):
|
| 85 |
-
"""Create a safe filename from text."""
|
| 86 |
-
#
|
| 87 |
-
safe_text = re.sub(r'[^\w\s-]', '
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 89 |
return safe_text[:50] # Limit length to 50 chars
|
| 90 |
|
| 91 |
-
def
|
| 92 |
-
"""
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
safe_query = sanitize_filename(query)
|
| 95 |
-
filename = f"ai_interaction_{timestamp}_{safe_query}.md"
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
## AI Response
|
| 104 |
{ai_result}
|
|
@@ -254,23 +271,14 @@ def file_management_sidebar():
|
|
| 254 |
def main():
|
| 255 |
st.title("Markdown Content with AI Lookup and File Management")
|
| 256 |
|
| 257 |
-
#
|
| 258 |
-
st.markdown("## Original Markdown Content")
|
| 259 |
-
st.markdown(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 260 |
-
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 261 |
-
|
| 262 |
-
# Parse and display terms with links
|
| 263 |
-
st.markdown("## Terms with Links")
|
| 264 |
-
terms1 = extract_terms(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 265 |
-
terms2 = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 266 |
-
all_terms = terms1 + terms2
|
| 267 |
-
display_terms_with_links(all_terms)
|
| 268 |
-
|
| 269 |
-
# Process query parameters and AI lookup
|
| 270 |
query_params = st.query_params
|
| 271 |
query = query_params.get('q', '')
|
|
|
|
| 272 |
|
|
|
|
| 273 |
if query:
|
|
|
|
| 274 |
st.write(f"### Search query received: {query}")
|
| 275 |
try:
|
| 276 |
ai_result = perform_ai_lookup(query)
|
|
@@ -287,10 +295,32 @@ def main():
|
|
| 287 |
# File management sidebar
|
| 288 |
file_management_sidebar()
|
| 289 |
|
| 290 |
-
# Display selected file
|
| 291 |
if st.session_state.selected_file:
|
|
|
|
| 292 |
st.markdown(f"### Current File: {st.session_state.selected_file}")
|
| 293 |
display_file_content(st.session_state.selected_file)
|
| 294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
if __name__ == "__main__":
|
| 296 |
main()
|
|
|
|
| 3 |
import glob
|
| 4 |
import re
|
| 5 |
import base64
|
| 6 |
+
import pytz
|
| 7 |
from urllib.parse import quote
|
| 8 |
from gradio_client import Client
|
| 9 |
from datetime import datetime
|
|
|
|
| 83 |
"""
|
| 84 |
|
| 85 |
def sanitize_filename(text):
|
| 86 |
+
"""Create a safe filename from text while preserving spaces."""
|
| 87 |
+
# First replace unsafe characters with spaces
|
| 88 |
+
safe_text = re.sub(r'[^\w\s-]', ' ', text)
|
| 89 |
+
# Remove any multiple spaces
|
| 90 |
+
safe_text = re.sub(r'\s+', ' ', safe_text)
|
| 91 |
+
# Trim leading/trailing spaces
|
| 92 |
+
safe_text = safe_text.strip()
|
| 93 |
return safe_text[:50] # Limit length to 50 chars
|
| 94 |
|
| 95 |
+
def generate_timestamp_filename(query):
|
| 96 |
+
"""Generate filename with format: 1103AM 11032024 (Query).md"""
|
| 97 |
+
# Get current time in Central timezone
|
| 98 |
+
central = pytz.timezone('US/Central')
|
| 99 |
+
current_time = datetime.now(central)
|
| 100 |
+
|
| 101 |
+
# Format the timestamp parts
|
| 102 |
+
time_str = current_time.strftime("%I%M%p") # 1103AM format
|
| 103 |
+
date_str = current_time.strftime("%m%d%Y") # 11032024 format
|
| 104 |
+
|
| 105 |
+
# Clean up the query for filename - now preserving spaces
|
| 106 |
safe_query = sanitize_filename(query)
|
|
|
|
| 107 |
|
| 108 |
+
# Construct filename: "1103AM 11032024 (Input with spaces).md"
|
| 109 |
+
filename = f"{time_str} {date_str} ({safe_query}).md"
|
| 110 |
+
|
| 111 |
+
return filename
|
| 112 |
|
| 113 |
+
def save_ai_interaction(query, ai_result):
|
| 114 |
+
"""Save AI interaction to a markdown file with new filename format."""
|
| 115 |
+
filename = generate_timestamp_filename(query)
|
| 116 |
+
|
| 117 |
+
# Format the content
|
| 118 |
+
content = f"""# Query: {query}
|
| 119 |
|
| 120 |
## AI Response
|
| 121 |
{ai_result}
|
|
|
|
| 271 |
def main():
|
| 272 |
st.title("Markdown Content with AI Lookup and File Management")
|
| 273 |
|
| 274 |
+
# Process query parameters and AI lookup first
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
query_params = st.query_params
|
| 276 |
query = query_params.get('q', '')
|
| 277 |
+
show_initial_content = True # Flag to control initial content display
|
| 278 |
|
| 279 |
+
# First priority: Handle active query
|
| 280 |
if query:
|
| 281 |
+
show_initial_content = False # Hide initial content when showing query results
|
| 282 |
st.write(f"### Search query received: {query}")
|
| 283 |
try:
|
| 284 |
ai_result = perform_ai_lookup(query)
|
|
|
|
| 295 |
# File management sidebar
|
| 296 |
file_management_sidebar()
|
| 297 |
|
| 298 |
+
# Second priority: Display selected file content if any
|
| 299 |
if st.session_state.selected_file:
|
| 300 |
+
show_initial_content = False # Hide initial content when showing file content
|
| 301 |
st.markdown(f"### Current File: {st.session_state.selected_file}")
|
| 302 |
display_file_content(st.session_state.selected_file)
|
| 303 |
|
| 304 |
+
# Show initial content: Either when first landing or when no interactive elements are active
|
| 305 |
+
if show_initial_content:
|
| 306 |
+
# First show the clickable terms with links
|
| 307 |
+
terms1 = extract_terms(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 308 |
+
terms2 = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 309 |
+
all_terms = terms1 + terms2
|
| 310 |
+
|
| 311 |
+
col1, col2 = st.columns(2)
|
| 312 |
+
|
| 313 |
+
with col1:
|
| 314 |
+
st.markdown("### Boxing & MMA")
|
| 315 |
+
st.markdown(Boxing_and_MMA_Commentary_and_Knowledge)
|
| 316 |
+
st.markdown("#### Related Links")
|
| 317 |
+
display_terms_with_links(terms1)
|
| 318 |
+
|
| 319 |
+
with col2:
|
| 320 |
+
st.markdown("### Multiplayer Games")
|
| 321 |
+
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
| 322 |
+
st.markdown("#### Related Links")
|
| 323 |
+
display_terms_with_links(terms2)
|
| 324 |
+
|
| 325 |
if __name__ == "__main__":
|
| 326 |
main()
|