ajayspot commited on
Commit
2611e90
·
verified ·
1 Parent(s): 498881e

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. evaluate_atomic_matching.py +57 -0
evaluate_atomic_matching.py CHANGED
@@ -11,6 +11,7 @@ import getpass
11
  import shutil
12
  import tempfile
13
  import subprocess
 
14
 
15
  # Initialize instructor client
16
  client = instructor.from_litellm(completion)
@@ -202,6 +203,62 @@ def process_questions(llm_model: str, openai_api_Key: str, deploy_key: str, metr
202
  error_message = f"Error pushing to repository: {str(e)}\nResults were saved locally to: {filepath}"
203
  return error_message, filepath # Return filepath even on git error
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  # Create Gradio interface
206
  with gr.Blocks(css="footer {visibility: hidden}") as iface:
207
  gr.Markdown("# Question Evaluation Tool")
 
11
  import shutil
12
  import tempfile
13
  import subprocess
14
+ import stat
15
 
16
  # Initialize instructor client
17
  client = instructor.from_litellm(completion)
 
203
  error_message = f"Error pushing to repository: {str(e)}\nResults were saved locally to: {filepath}"
204
  return error_message, filepath # Return filepath even on git error
205
 
206
+ def setup_ssh_key(ssh_key_content):
207
+ try:
208
+ validate_ssh_key(ssh_key_content)
209
+ except ValueError as e:
210
+ raise ValueError(f"Invalid SSH key: {str(e)}")
211
+
212
+ # Create .ssh directory if it doesn't exist
213
+ ssh_dir = os.path.expanduser('~/.ssh')
214
+ os.makedirs(ssh_dir, exist_ok=True)
215
+
216
+ # Save the key to a file
217
+ key_path = os.path.join(ssh_dir, 'github_deploy_key')
218
+ with open(key_path, 'w') as f:
219
+ f.write(ssh_key_content)
220
+
221
+ # Set correct permissions (600)
222
+ os.chmod(key_path, stat.S_IRUSR | stat.S_IWUSR)
223
+
224
+ # Configure ssh to use this key for github.com
225
+ config_path = os.path.join(ssh_dir, 'config')
226
+ config_content = f"""Host github.com
227
+ HostName github.com
228
+ IdentityFile {key_path}
229
+ User git
230
+ """
231
+
232
+ with open(config_path, 'w') as f:
233
+ f.write(config_content)
234
+
235
+ # Set correct permissions for .ssh directory
236
+ os.chmod(ssh_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
237
+
238
+ return key_path
239
+
240
+ def handle_ssh_key(ssh_key):
241
+ try:
242
+ key_path = setup_ssh_key(ssh_key)
243
+ # Test the SSH connection
244
+ result = subprocess.run(['ssh', '-T', 'git@github.com'],
245
+ capture_output=True,
246
+ text=True)
247
+ return f"SSH key setup complete. Key saved to {key_path}"
248
+ except Exception as e:
249
+ return f"Error setting up SSH key: {str(e)}"
250
+
251
+ def validate_ssh_key(key_content):
252
+ # Check if it looks like a private key
253
+ if not key_content.startswith('-----BEGIN'):
254
+ raise ValueError("Invalid key format")
255
+
256
+ # Check if it's complete
257
+ if not key_content.strip().endswith('-----END'):
258
+ raise ValueError("Incomplete key")
259
+
260
+ return True
261
+
262
  # Create Gradio interface
263
  with gr.Blocks(css="footer {visibility: hidden}") as iface:
264
  gr.Markdown("# Question Evaluation Tool")