akhaliq HF Staff commited on
Commit
b171e23
·
1 Parent(s): 999c623

cleaned code

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -6876,16 +6876,19 @@ Generate a comprehensive requirements.txt that ensures the application will work
6876
 
6877
  # Clean up the response in case it includes extra formatting
6878
  if '```' in requirements_content:
6879
- # Extract content between code blocks
 
 
 
 
6880
  lines = requirements_content.split('\n')
6881
- in_code_block = False
6882
  clean_lines = []
6883
  for line in lines:
6884
- if line.strip().startswith('```'):
6885
- in_code_block = not in_code_block
 
6886
  continue
6887
- if in_code_block:
6888
- clean_lines.append(line)
6889
  requirements_content = '\n'.join(clean_lines).strip()
6890
 
6891
  # Ensure it ends with a newline
@@ -9538,9 +9541,23 @@ with gr.Blocks(
9538
 
9539
  # Create CommitOperation for each file
9540
  for filename, content in files.items():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9541
  # Create temporary file
9542
  with tempfile.NamedTemporaryFile("w", suffix=f".{filename.split('.')[-1]}", delete=False) as f:
9543
- f.write(content)
9544
  temp_path = f.name
9545
  temp_files.append(temp_path)
9546
 
 
6876
 
6877
  # Clean up the response in case it includes extra formatting
6878
  if '```' in requirements_content:
6879
+ # Use the existing remove_code_block function for consistent cleaning
6880
+ requirements_content = remove_code_block(requirements_content)
6881
+
6882
+ # Additional cleanup for any remaining backticks
6883
+ # Remove any remaining standalone backticks at start/end of lines
6884
  lines = requirements_content.split('\n')
 
6885
  clean_lines = []
6886
  for line in lines:
6887
+ stripped_line = line.strip()
6888
+ # Skip lines that are just backticks or backticks with language markers
6889
+ if stripped_line == '```' or stripped_line.startswith('```'):
6890
  continue
6891
+ clean_lines.append(line)
 
6892
  requirements_content = '\n'.join(clean_lines).strip()
6893
 
6894
  # Ensure it ends with a newline
 
9541
 
9542
  # Create CommitOperation for each file
9543
  for filename, content in files.items():
9544
+ # Clean content to ensure no stray backticks are deployed
9545
+ cleaned_content = content
9546
+ if filename.endswith('.txt') or filename.endswith('.py'):
9547
+ # Additional safety: remove any standalone backtick lines
9548
+ lines = cleaned_content.split('\n')
9549
+ clean_lines = []
9550
+ for line in lines:
9551
+ stripped = line.strip()
9552
+ # Skip lines that are just backticks
9553
+ if stripped == '```' or (stripped.startswith('```') and len(stripped) <= 10):
9554
+ continue
9555
+ clean_lines.append(line)
9556
+ cleaned_content = '\n'.join(clean_lines)
9557
+
9558
  # Create temporary file
9559
  with tempfile.NamedTemporaryFile("w", suffix=f".{filename.split('.')[-1]}", delete=False) as f:
9560
+ f.write(cleaned_content)
9561
  temp_path = f.name
9562
  temp_files.append(temp_path)
9563