Spaces:
Runtime error
Runtime error
Update app.py
Browse files54 unmodified lines5556575859606117 unmodified lines798081828381848586871 unmodified line8990918992939493959697983 unmodified lines1021031041031051061071081 unmodified line11011111211311411511654 unmodified lines# Define a context dictionary to maintain the state between exec callscontext = {}
def create_file(filename, prompt, response, should_save=True): if not should_save: return17 unmodified lines if "python" in resource.lower(): # Remove the 'python' keyword from the code block cleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE) # Add Code Results title with markdown and emoji combined_content += "### Code Execution Results ๐\n" combined_content += "# Code Results ๐\n"
# Redirect standard output to capture it original_stdout = sys.stdout1 unmodified line # Execute the cleaned Python code within the context try: st.write('Executing code: ', cleaned_code) exec(cleaned_code, context) code_output = sys.stdout.getvalue() combined_content += f"```\n{code_output}\n```\n\n" realtimeEvalResponse = "### Code Execution Results ๐\n" + "```" + code_output + "```\n\n" realtimeEvalResponse = "# Code Results ๐\n" + "```" + code_output + "```\n\n" st.write(realtimeEvalResponse) except Exception as e:3 unmodified lines sys.stdout = original_stdout else: # Add non-Python resources with markdown and emoji combined_content += "### Resource Added For New Tool ๐ ๏ธ\n" + "```" + resource + "```\n\n" combined_content += "# Resource ๐ ๏ธ\n" + "```" + resource + "```\n\n"
# Save the combined content to a Markdown file if should_save:1 unmodified line file.write(combined_content)
# Read it aloud def readitaloud(result): documentHTML5='''app.py+7-4