Spaces:
Runtime error
Runtime error
Update app.py
Browse files67 unmodified lines68697071727374752 unmodified lines78798079818283848586838788899085919293949596979882 unmodified lines18118218317518418518618718818967 unmodified lines combined_content += "# Response 💬\n" + response + "\n\n"
# Extract Python code blocks from the response allcodeandcodeexec = '' resources = re.findall(r"```python([\s\S]*?)```", response) for resource in resources: combined_content += "# Code Results 🚀\n"2 unmodified lines with io.StringIO() as buf: with redirect_stdout(buf): try: # Remove the 'python' keyword from the code block 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 += realtimeEvalResponse exec(cleaned_code.strip()) code_output = buf.getvalue() combined_content += f"```\n{code_output}\n```\n\n" realtimeEvalResponse = "## Executed Code Result 🚀\n" + "```" + code_output + "```\n\n" # st.write(realtimeEvalResponse) combined_content += realtimeEvalResponse except Exception as e: combined_content += f"```python\nError executing Python code: {e}\n```\n\n" realtimeEvalResponse = "## Executed Code Error 🚀\n" + f"```python\nError executing Python code: {e}\n```\n\n" combined_content += realtimeEvalResponse
st.markdown(combined_content) # Save the combined content to a Markdown file if should_save: with open(filename, 'w') as file:82 unmodified lines full_reply_content = all_content st.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) readitaloud(full_reply_content) return full_reply_content
def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):app.py+13-4