Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- evaluate_atomic_matching.py +12 -47
evaluate_atomic_matching.py
CHANGED
|
@@ -98,55 +98,20 @@ def process_questions(llm_model: str, openai_api_Key: str, deploy_key: str, metr
|
|
| 98 |
with open(filepath, 'w') as f:
|
| 99 |
json.dump(results, f, indent=4)
|
| 100 |
|
| 101 |
-
# Push to git repo and verify
|
| 102 |
try:
|
| 103 |
-
#
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
deploy_key_cleaned = deploy_key.strip()
|
| 110 |
-
|
| 111 |
-
# Ensure key has proper line endings and format
|
| 112 |
-
key_lines = deploy_key_cleaned.split('\n')
|
| 113 |
-
key_lines = [line.strip() for line in key_lines] # Remove any extra whitespace
|
| 114 |
-
deploy_key_cleaned = '\n'.join(key_lines)
|
| 115 |
-
|
| 116 |
-
# Ensure the key ends with a newline
|
| 117 |
-
if not deploy_key_cleaned.endswith('\n'):
|
| 118 |
-
deploy_key_cleaned += '\n'
|
| 119 |
-
|
| 120 |
-
# Write the key with proper permissions
|
| 121 |
-
with open(key_file, 'w', newline='\n') as f:
|
| 122 |
-
f.write(deploy_key_cleaned)
|
| 123 |
-
|
| 124 |
-
# Ensure correct permissions for SSH key
|
| 125 |
-
os.chmod(key_file, 0o600)
|
| 126 |
-
|
| 127 |
-
# Print key file contents for debugging (remove in production)
|
| 128 |
-
with open(key_file, 'r') as f:
|
| 129 |
-
key_content = f.read()
|
| 130 |
-
if not key_content.startswith('-----BEGIN'):
|
| 131 |
-
raise Exception("Key file validation failed - incorrect format")
|
| 132 |
-
|
| 133 |
-
# Set up Git SSH command with more verbose output
|
| 134 |
-
ssh_command = f'ssh -vvv -i {key_file} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
| 135 |
-
os.environ['GIT_SSH_COMMAND'] = ssh_command
|
| 136 |
-
|
| 137 |
# Test SSH connection
|
| 138 |
try:
|
| 139 |
-
result = subprocess.run(
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
capture_output=True,
|
| 143 |
-
text=True,
|
| 144 |
-
timeout=10
|
| 145 |
-
)
|
| 146 |
if result.returncode != 1: # GitHub's SSH test always returns 1 when successful
|
| 147 |
raise Exception(f"SSH test failed with return code {result.returncode}\nOutput: {result.stderr}")
|
| 148 |
-
except subprocess.CalledProcessError as e:
|
| 149 |
-
raise Exception(f"SSH connection test failed: {e.stderr if e.stderr else str(e)}")
|
| 150 |
except Exception as e:
|
| 151 |
raise Exception(f"SSH connection test failed: {str(e)}")
|
| 152 |
|
|
@@ -189,19 +154,19 @@ def process_questions(llm_model: str, openai_api_Key: str, deploy_key: str, metr
|
|
| 189 |
except Exception as e:
|
| 190 |
raise Exception(f"Git operation failed: {str(e)}")
|
| 191 |
finally:
|
| 192 |
-
#
|
| 193 |
try:
|
| 194 |
shutil.rmtree(temp_dir)
|
| 195 |
except:
|
| 196 |
pass
|
| 197 |
try:
|
| 198 |
-
os.remove(
|
| 199 |
except:
|
| 200 |
pass
|
| 201 |
|
| 202 |
except Exception as e:
|
| 203 |
error_message = f"Error pushing to repository: {str(e)}\nResults were saved locally to: {filepath}"
|
| 204 |
-
return error_message, filepath
|
| 205 |
|
| 206 |
def setup_ssh_key(ssh_key_content):
|
| 207 |
try:
|
|
|
|
| 98 |
with open(filepath, 'w') as f:
|
| 99 |
json.dump(results, f, indent=4)
|
| 100 |
|
|
|
|
| 101 |
try:
|
| 102 |
+
# Set up SSH key before git operations
|
| 103 |
+
try:
|
| 104 |
+
key_path = setup_ssh_key(deploy_key)
|
| 105 |
+
except Exception as e:
|
| 106 |
+
raise Exception(f"Failed to set up SSH key: {str(e)}")
|
| 107 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
# Test SSH connection
|
| 109 |
try:
|
| 110 |
+
result = subprocess.run(['ssh', '-T', 'git@github.com'],
|
| 111 |
+
capture_output=True,
|
| 112 |
+
text=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
if result.returncode != 1: # GitHub's SSH test always returns 1 when successful
|
| 114 |
raise Exception(f"SSH test failed with return code {result.returncode}\nOutput: {result.stderr}")
|
|
|
|
|
|
|
| 115 |
except Exception as e:
|
| 116 |
raise Exception(f"SSH connection test failed: {str(e)}")
|
| 117 |
|
|
|
|
| 154 |
except Exception as e:
|
| 155 |
raise Exception(f"Git operation failed: {str(e)}")
|
| 156 |
finally:
|
| 157 |
+
# Clean up
|
| 158 |
try:
|
| 159 |
shutil.rmtree(temp_dir)
|
| 160 |
except:
|
| 161 |
pass
|
| 162 |
try:
|
| 163 |
+
os.remove(key_path) # Remove the SSH key file
|
| 164 |
except:
|
| 165 |
pass
|
| 166 |
|
| 167 |
except Exception as e:
|
| 168 |
error_message = f"Error pushing to repository: {str(e)}\nResults were saved locally to: {filepath}"
|
| 169 |
+
return error_message, filepath
|
| 170 |
|
| 171 |
def setup_ssh_key(ssh_key_content):
|
| 172 |
try:
|