For the folloinwg code: Generate button if st.button("🎯 Generate Slides",…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
For the folloinwg code:
if st.button("🎯 Generate Slides", type="primary", use_container_width=True):
with st.spinner("Generating presentation... This may take a moment."):
try:
# Get the SAA instance
json_path = os.path.abspath('cache/cache.json')
saa = ScalableSAA(json_path)
# Set the results container
saa.rc = st.session_state.results
# Generate slides and get the expected path
expected_path = saa.generate_slides_subprocess()
# Check if we got a valid path
if expected_path is None:
st.error("Slide generation returned no path. Checking for files...")
# Try to construct the expected path manually
if hasattr(saa, 'paths') and hasattr(saa, 'run_key'):
slide_deck_out_folder = saa.paths.folders.get('slide_deck_out')
if slide_deck_out_folder:
expected_path = os.path.join(slide_deck_out_folder, f'{saa.run_key}.pptx')
st.info(f"Checking for file at: {expected_path}")
else:
st.error("Could not determine output folder from SAA instance")
else:
st.error("SAA instance missing required attributes (paths or run_key)")
if expected_path:
# Wait for the file to be created (max 30 seconds)
max_wait_time = 30
wait_interval = 0.5
elapsed_time = 0
st.info(f"Waiting for file at: {expected_path}")
while elapsed_time < max_wait_time:
if os.path.exists(expected_path):
# File exists, wait a bit more to ensure it's fully written
time.sleep(1)
# Verify file size is stable (not still being written)
try:
initial_size = os.path.getsize(expected_path)
time.sleep(0.5)
final_size = os.path.getsize(expected_path)
if initial_size == final_size and final_size > 0:
st.session_state.slides_path = expected_path
st.session_state.slides_generated = True
st.success(f"File found! Size: {final_size / (1024*1024):.2f} MB")
st.rerun()
break
except Exception as e:
st.warning(f"Error checking file size: {e}")
time.sleep(wait_interval)
elapsed_time += wait_interval
if not st.session_state.slides_generated:
st.error(f"File was not created after {max_wait_time} seconds")
# Check if directory exists and list contents
if expected_path:
expected_dir = os.path.dirname(expected_path)
if os.path.exists(expected_dir):
files = os.listdir(expected_dir)
st.info(f"Files in {expected_dir}: {files}")
# Look for any .pptx files
pptx_files = [f for f in files if f.endswith('.pptx')]
if pptx_files:
st.info(f"Found PowerPoint files: {pptx_files}")
# Use the most recent one
latest_file = max(pptx_files, key=lambda f: os.path.getctime(os.path.join(expected_dir, f)))
latest_path = os.path.join(expected_dir, latest_file)
st.session_state.slides_path = latest_path
st.session_state.slides_generated = True
st.success(f"Using file: {latest_file}")
st.rerun()
else:
st.error(f"Output directory does not exist: {expected_dir}")
# Try to create it
try:
os.makedirs(expected_dir, exist_ok=True)
st.info(f"Created directory: {expected_dir}")
except Exception as e:
st.error(f"Could not create directory: {e}")
except Exception as e:
st.error(f"❌ Error generating slides: {str(e)}")
logging.error(f"Slide generation error: {str(e)}", exc_info=True)
st.session_state.slides_generated = False
# Try to provide more debugging info
if hasattr(locals(), 'saa'):
st.info("SAA instance attributes:")
if hasattr(saa, 'paths'):
st.info(f"- Has paths: Yes")
if hasattr(saa.paths, 'folders'):
st.info(f"- Folders: {list(saa.paths.folders.keys())}")
else:
st.info(f"- Has paths: No")
if hasattr(saa, 'run_key'):
st.info(f"- Run key: {saa.run_key}")
else:
st.info(f"- Has run_key: No")
# Download button - only show if slides have been generated
if st.session_state.slides_generated and st.session_state.slides_path:
if os.path.exists(st.session_state.slides_path):
try:
with open(st.session_state.slides_path, "rb") as file:
file_data = file.read()
st.download_button(
label="📥 Download Presentation",
data=file_data,
file_name=f"presentation_{time.strftime('%Y%m%d_%H%M%S')}.pptx",
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation",
use_container_width=True
)
st.success("✅ Presentation ready for download!")
except Exception as e:
st.error(f"Error reading file: {str(e)}")
st.session_state.slides_generated = False
else:
st.warning("Generated file not found. Please regenerate.")
st.session_state.slides_generated = False
# File information - always show if slides have been generated
if st.session_state.slides_path and st.session_state.slides_generated:
with st.expander("📁 File Information", expanded=False):
st.text(f"Location: {st.session_state.slides_path}")
if os.path.exists(st.session_state.slides_path):
file_size = os.path.getsize(st.session_state.slides_path) / (1024 * 1024) # Convert to MB
st.text(f"Size: {file_size:.2f} MB")
mod_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(os.path.getmtime(st.session_state.slides_path)))
st.text(f"Generated: {mod_time}")
else: st.error("No analysis results available. Please run optimization first.")
I get this weird error but I dont know why
PermissionError: [Errno 13] Permission denied: 'C:\Users\knolseb\dev\ScalableSAA_engine\cache\cover.pptx'
The error occurs because the program cannot access the file 'cover.pptx' due to permission issues. This could be because the file is open in another application, the user lacks the necessary permissions, or the file is locked. To resolve this issue, ensure that the file is not in use by another process and that the user has read/write permissions for the file. Additionally, consider copying the file to a temporary location if access issues persist.
Here's a step-by-step approach to fix the issue:
Example code to handle file accessibility:
import os
import shutil
import tempfile
def ensure_file_accessible(file_path):
if not os.path.exists(file_path):
raise FileNotFoundError(f"File not found: {file_path}")
# Check if file is readable
try:
with open(file_path, 'rb') as f:
pass
except PermissionError:
# Try to copy the file to a temporary location
temp_dir = tempfile.mkdtemp()
temp_path = os.path.join(temp_dir, os.path.basename(file_path))
shutil.copy2(file_path, temp_path)
return temp_path
except Exception as e:
raise Exception(f"Error accessing file: {e}")
return file_path
# Usage
try:
accessible_path = ensure_file_accessible('C:\\Users\\knolseb\\dev\\ScalableSAA_engine\\cache\\cover.pptx')
# Use accessible_path instead of the original path in your code
except Exception as e:
print(f"Error ensuring file accessibility: {e}")
By following these steps, you should be able to resolve the permission error and successfully generate the slides.