shukdevdatta123 commited on
Commit
ee73624
·
verified ·
1 Parent(s): 811bed9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
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 = not in_code
43
- if not in_code:
44
- formatted.append(f"```python\n{'\n'.join(code_buffer[1:])}\n```")
 
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: