Spaces:
Runtime error
Runtime error
Update app.py
Browse files67 unmodified lines6869707172732 unmodified lines767778798081828384858687888982 unmodified lines17217317417517617717817918067 unmodified linescombined_content += "# Response π¬\n" + response + "\n\n"# Extract Python code blocks from the responseresources = re.findall(r"```python([\s\S]*?)```", response)for resource in resources:combined_content += "# Code Results π\n"2 unmodified lineswith io.StringIO() as buf:with redirect_stdout(buf):try:# Remove the 'python' keyword from the code blockcleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)exec(cleaned_code.strip())code_output = buf.getvalue()combined_content += f"```\n{code_output}\n```\n\n"except Exception as e:combined_content += f"```python\nError executing Python code: {e}\n```\n\n"# Save the combined content to a Markdown fileif should_save:with open(filename, 'w') as file:82 unmodified linesfull_reply_content = all_contentst.write("Elapsed time:")st.write(time.time() - start_time)readitaloud(full_reply_content)filename = generate_filename(full_reply_content, choice)create_file(filename, prompt, full_reply_content, should_save)return full_reply_contentdef chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):67 unmodified lines68697071727374752 unmodified lines78798081828384858687888990919293949596979882 unmodified lines18118218318418518618718818967 unmodified linescombined_content += "# Response π¬\n" + response + "\n\n"# Extract Python code blocks from the responseallcodeandcodeexec = ''resources = re.findall(r"```python([\s\S]*?)```", response)for resource in resources:combined_content += "# Code Results π\n"2 unmodified lineswith io.StringIO() as buf:with redirect_stdout(buf):try:cleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)realtimeEvalResponse = "## Executing Code Block π\n" + "```" + cleaned_code + "```\n\n"# st.write(realtimeEvalResponse)combined_content += realtimeEvalResponseexec(cleaned_code.strip())code_output = buf.getvalue()realtimeEvalResponse = "## Executed Code Result π\n" + "```" + code_output + "```\n\n"# st.write(realtimeEvalResponse)combined_content += realtimeEvalResponseexcept Exception as e:realtimeEvalResponse = "## Executed Code Error π\n" + f"```python\nError executing Python code: {e}\n```\n\n"combined_content += realtimeEvalResponsest.markdown(combined_content)# Save the combined content to a Markdown fileif should_save:with open(filename, 'w') as file:82 unmodified linesfull_reply_content = all_contentst.write("Elapsed time:")st.write(time.time() - start_time)filename = generate_filename(full_reply_content, choice)create_file(filename, prompt, full_reply_content, should_save)readitaloud(full_reply_content)return full_reply_contentdef chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
app.py+13-4