Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,6 @@ def generate_solution(api_key, problem_statement):
|
|
31 |
return f"Error: {str(e)}"
|
32 |
|
33 |
def format_response(response):
|
34 |
-
# Split code and explanation
|
35 |
formatted = []
|
36 |
in_code = False
|
37 |
code_buffer = []
|
@@ -39,10 +38,12 @@ def format_response(response):
|
|
39 |
|
40 |
for line in response.split('\n'):
|
41 |
if line.strip().startswith('```'):
|
42 |
-
in_code
|
43 |
-
|
44 |
-
|
|
|
45 |
code_buffer = []
|
|
|
46 |
continue
|
47 |
|
48 |
if in_code:
|
|
|
31 |
return f"Error: {str(e)}"
|
32 |
|
33 |
def format_response(response):
|
|
|
34 |
formatted = []
|
35 |
in_code = False
|
36 |
code_buffer = []
|
|
|
38 |
|
39 |
for line in response.split('\n'):
|
40 |
if line.strip().startswith('```'):
|
41 |
+
if in_code and code_buffer:
|
42 |
+
# Fix: Separate string concatenation
|
43 |
+
code_content = '\n'.join(code_buffer[1:]) # Remove first line (language marker)
|
44 |
+
formatted.append(f"```python\n{code_content}\n```")
|
45 |
code_buffer = []
|
46 |
+
in_code = not in_code
|
47 |
continue
|
48 |
|
49 |
if in_code:
|