Spaces:
Runtime error
Runtime error
Update app.py
Browse files54 unmodified lines55565758596017 unmodified lines787980818283841 unmodified line86878889909192939495963 unmodified lines1001011021031041051061 unmodified line10810911011111211354 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 linesif "python" in resource.lower():# Remove the 'python' keyword from the code blockcleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)combined_content += "### Code Execution Results ๐\n"# Redirect standard output to capture itoriginal_stdout = sys.stdout1 unmodified line# Execute the cleaned Python code within the contexttry: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"st.write(realtimeEvalResponse)except Exception as e:3 unmodified linessys.stdout = original_stdoutelse:# Add non-Python resources with markdown and emojicombined_content += "### Resource Added For New Tool ๐ ๏ธ\n" + "```" + resource + "```\n\n"# Save the combined content to a Markdown fileif should_save:1 unmodified linefile.write(combined_content)# Read it alouddef readitaloud(result):documentHTML5='''54 unmodified lines5556575859606117 unmodified lines7980818283848586871 unmodified line899091929394959697983 unmodified lines1021031041051061071081 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 linesif "python" in resource.lower():# Remove the 'python' keyword from the code blockcleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)# Add Code Results title with markdown and emojicombined_content += "# Code Results ๐\n"# Redirect standard output to capture itoriginal_stdout = sys.stdout1 unmodified line# Execute the cleaned Python code within the contexttry:exec(cleaned_code, context)code_output = sys.stdout.getvalue()combined_content += f"```\n{code_output}\n```\n\n"realtimeEvalResponse = "# Code Results ๐\n" + "```" + code_output + "```\n\n"st.write(realtimeEvalResponse)except Exception as e:3 unmodified linessys.stdout = original_stdoutelse:# Add non-Python resources with markdown and emojicombined_content += "# Resource ๐ ๏ธ\n" + "```" + resource + "```\n\n"# Save the combined content to a Markdown fileif should_save:1 unmodified linefile.write(combined_content)# Read it alouddef readitaloud(result):documentHTML5='''
app.py+7-4