Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -55,6 +55,7 @@ with col1:
|
|
55 |
# Define a context dictionary to maintain the state between exec calls
|
56 |
context = {}
|
57 |
|
|
|
58 |
def create_file(filename, prompt, response, should_save=True):
|
59 |
if not should_save:
|
60 |
return
|
@@ -78,7 +79,9 @@ def create_file(filename, prompt, response, should_save=True):
|
|
78 |
if "python" in resource.lower():
|
79 |
# Remove the 'python' keyword from the code block
|
80 |
cleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)
|
81 |
-
|
|
|
|
|
82 |
|
83 |
# Redirect standard output to capture it
|
84 |
original_stdout = sys.stdout
|
@@ -86,11 +89,10 @@ def create_file(filename, prompt, response, should_save=True):
|
|
86 |
|
87 |
# Execute the cleaned Python code within the context
|
88 |
try:
|
89 |
-
st.write('Executing code: ', cleaned_code)
|
90 |
exec(cleaned_code, context)
|
91 |
code_output = sys.stdout.getvalue()
|
92 |
combined_content += f"```\n{code_output}\n```\n\n"
|
93 |
-
realtimeEvalResponse = "
|
94 |
st.write(realtimeEvalResponse)
|
95 |
|
96 |
except Exception as e:
|
@@ -100,7 +102,7 @@ def create_file(filename, prompt, response, should_save=True):
|
|
100 |
sys.stdout = original_stdout
|
101 |
else:
|
102 |
# Add non-Python resources with markdown and emoji
|
103 |
-
combined_content += "
|
104 |
|
105 |
# Save the combined content to a Markdown file
|
106 |
if should_save:
|
@@ -108,6 +110,7 @@ def create_file(filename, prompt, response, should_save=True):
|
|
108 |
file.write(combined_content)
|
109 |
|
110 |
|
|
|
111 |
# Read it aloud
|
112 |
def readitaloud(result):
|
113 |
documentHTML5='''
|
|
|
55 |
# Define a context dictionary to maintain the state between exec calls
|
56 |
context = {}
|
57 |
|
58 |
+
|
59 |
def create_file(filename, prompt, response, should_save=True):
|
60 |
if not should_save:
|
61 |
return
|
|
|
79 |
if "python" in resource.lower():
|
80 |
# Remove the 'python' keyword from the code block
|
81 |
cleaned_code = re.sub(r'^\s*python', '', resource, flags=re.IGNORECASE | re.MULTILINE)
|
82 |
+
|
83 |
+
# Add Code Results title with markdown and emoji
|
84 |
+
combined_content += "# Code Results π\n"
|
85 |
|
86 |
# Redirect standard output to capture it
|
87 |
original_stdout = sys.stdout
|
|
|
89 |
|
90 |
# Execute the cleaned Python code within the context
|
91 |
try:
|
|
|
92 |
exec(cleaned_code, context)
|
93 |
code_output = sys.stdout.getvalue()
|
94 |
combined_content += f"```\n{code_output}\n```\n\n"
|
95 |
+
realtimeEvalResponse = "# Code Results π\n" + "```" + code_output + "```\n\n"
|
96 |
st.write(realtimeEvalResponse)
|
97 |
|
98 |
except Exception as e:
|
|
|
102 |
sys.stdout = original_stdout
|
103 |
else:
|
104 |
# Add non-Python resources with markdown and emoji
|
105 |
+
combined_content += "# Resource π οΈ\n" + "```" + resource + "```\n\n"
|
106 |
|
107 |
# Save the combined content to a Markdown file
|
108 |
if should_save:
|
|
|
110 |
file.write(combined_content)
|
111 |
|
112 |
|
113 |
+
|
114 |
# Read it aloud
|
115 |
def readitaloud(result):
|
116 |
documentHTML5='''
|