awacke1 commited on
Commit
62e9061
Β·
1 Parent(s): eba106b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -68,6 +68,8 @@ def create_file(filename, prompt, response, should_save=True):
68
  combined_content += "# Response πŸ’¬\n" + response + "\n\n"
69
 
70
  # Extract Python code blocks from the response
 
 
71
  resources = re.findall(r"```python([\s\S]*?)```", response)
72
  for resource in resources:
73
  combined_content += "# Code Results πŸš€\n"
@@ -76,14 +78,21 @@ def create_file(filename, prompt, response, should_save=True):
76
  with io.StringIO() as buf:
77
  with redirect_stdout(buf):
78
  try:
79
- # Remove the 'python' keyword from the code block
80
  cleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)
 
 
 
81
  exec(cleaned_code.strip())
82
  code_output = buf.getvalue()
83
- combined_content += f"```\n{code_output}\n```\n\n"
 
 
84
  except Exception as e:
85
- combined_content += f"```python\nError executing Python code: {e}\n```\n\n"
 
86
 
 
 
87
  # Save the combined content to a Markdown file
88
  if should_save:
89
  with open(filename, 'w') as file:
@@ -172,9 +181,9 @@ def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
172
  full_reply_content = all_content
173
  st.write("Elapsed time:")
174
  st.write(time.time() - start_time)
175
- readitaloud(full_reply_content)
176
  filename = generate_filename(full_reply_content, choice)
177
  create_file(filename, prompt, full_reply_content, should_save)
 
178
  return full_reply_content
179
 
180
  def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
 
68
  combined_content += "# Response πŸ’¬\n" + response + "\n\n"
69
 
70
  # Extract Python code blocks from the response
71
+ allcodeandcodeexec = ''
72
+
73
  resources = re.findall(r"```python([\s\S]*?)```", response)
74
  for resource in resources:
75
  combined_content += "# Code Results πŸš€\n"
 
78
  with io.StringIO() as buf:
79
  with redirect_stdout(buf):
80
  try:
 
81
  cleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)
82
+ realtimeEvalResponse = "## Executing Code Block πŸš€\n" + "```" + cleaned_code + "```\n\n"
83
+ # st.write(realtimeEvalResponse)
84
+ combined_content += realtimeEvalResponse
85
  exec(cleaned_code.strip())
86
  code_output = buf.getvalue()
87
+ realtimeEvalResponse = "## Executed Code Result πŸš€\n" + "```" + code_output + "```\n\n"
88
+ # st.write(realtimeEvalResponse)
89
+ combined_content += realtimeEvalResponse
90
  except Exception as e:
91
+ realtimeEvalResponse = "## Executed Code Error πŸš€\n" + f"```python\nError executing Python code: {e}\n```\n\n"
92
+ combined_content += realtimeEvalResponse
93
 
94
+ st.markdown(combined_content)
95
+
96
  # Save the combined content to a Markdown file
97
  if should_save:
98
  with open(filename, 'w') as file:
 
181
  full_reply_content = all_content
182
  st.write("Elapsed time:")
183
  st.write(time.time() - start_time)
 
184
  filename = generate_filename(full_reply_content, choice)
185
  create_file(filename, prompt, full_reply_content, should_save)
186
+ readitaloud(full_reply_content)
187
  return full_reply_content
188
 
189
  def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):