ajayspot commited on
Commit
3c2faf0
·
verified ·
1 Parent(s): 95f7c07

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. evaluate_atomic_matching.py +42 -22
evaluate_atomic_matching.py CHANGED
@@ -9,6 +9,8 @@ from litellm import completion
9
  import json
10
  import getpass
11
  import shutil
 
 
12
 
13
  # Initialize instructor client
14
  client = instructor.from_litellm(completion)
@@ -97,24 +99,34 @@ def process_questions(llm_model: str, openai_api_Key: str, deploy_key: str, metr
97
 
98
  # Push to git repo and verify
99
  try:
100
- # Write deploy key to temporary file
101
  key_file = os.path.join(script_dir, "deploy_key")
102
- with open(key_file, 'w') as f:
103
- f.write(deploy_key)
 
 
 
104
  os.chmod(key_file, 0o600)
105
 
106
- # Set up Git SSH command
107
- os.environ['GIT_SSH_COMMAND'] = f'ssh -i {key_file} -o StrictHostKeyChecking=no'
 
108
 
109
- # Initialize repo with remote URL if it doesn't exist
 
 
 
 
 
 
 
 
 
 
110
  repo_url = "git@github.com:spotonix-inc/eval_results.git"
111
-
112
- # Create a temporary directory for cloning
113
- import tempfile
114
  temp_dir = tempfile.mkdtemp()
115
 
116
  try:
117
- # Clone into temporary directory
118
  repo = Repo.clone_from(repo_url, temp_dir)
119
 
120
  # Copy the new file to the cloned repo under atomic_concepts_gradio directory
@@ -137,19 +149,27 @@ def process_questions(llm_model: str, openai_api_Key: str, deploy_key: str, metr
137
  github_web_url = github_web_url.replace(".git", "")
138
  file_url = f"{github_web_url}/blob/main/atomic_concepts_gradio/{filename}"
139
 
140
- finally:
141
- # Clean up
142
- shutil.rmtree(temp_dir)
143
- os.remove(key_file)
 
 
 
 
144
 
145
- final_message = (
146
- f"Successfully processed {len(question_list)} questions.\n"
147
- f"Results saved to {filename} and pushed to repository.\n"
148
- f"View results at: {file_url}"
149
- )
150
- if error_messages:
151
- final_message += "\n\nErrors encountered:\n" + "\n".join(error_messages)
152
- return final_message, filepath
 
 
 
 
153
 
154
  except Exception as e:
155
  return f"Error pushing to repository: {str(e)}", None
 
9
  import json
10
  import getpass
11
  import shutil
12
+ import tempfile
13
+ import subprocess
14
 
15
  # Initialize instructor client
16
  client = instructor.from_litellm(completion)
 
99
 
100
  # Push to git repo and verify
101
  try:
102
+ # Write deploy key to temporary file with proper line endings
103
  key_file = os.path.join(script_dir, "deploy_key")
104
+ deploy_key_cleaned = deploy_key.strip().replace('\r\n', '\n')
105
+ with open(key_file, 'w', newline='\n') as f:
106
+ f.write(deploy_key_cleaned)
107
+
108
+ # Ensure correct permissions for SSH key
109
  os.chmod(key_file, 0o600)
110
 
111
+ # Set up Git SSH command with more verbose output for debugging
112
+ ssh_command = f'ssh -v -i {key_file} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
113
+ os.environ['GIT_SSH_COMMAND'] = ssh_command
114
 
115
+ # Test SSH connection before attempting clone
116
+ try:
117
+ subprocess.run(['ssh', '-T', '-i', key_file, '-o', 'StrictHostKeyChecking=no',
118
+ '-o', 'UserKnownHostsFile=/dev/null', 'git@github.com'],
119
+ capture_output=True, timeout=10)
120
+ except subprocess.CalledProcessError as e:
121
+ raise Exception(f"SSH connection test failed: {e.stderr.decode() if e.stderr else str(e)}")
122
+ except Exception as e:
123
+ raise Exception(f"SSH connection test failed: {str(e)}")
124
+
125
+ # Rest of the git operations
126
  repo_url = "git@github.com:spotonix-inc/eval_results.git"
 
 
 
127
  temp_dir = tempfile.mkdtemp()
128
 
129
  try:
 
130
  repo = Repo.clone_from(repo_url, temp_dir)
131
 
132
  # Copy the new file to the cloned repo under atomic_concepts_gradio directory
 
149
  github_web_url = github_web_url.replace(".git", "")
150
  file_url = f"{github_web_url}/blob/main/atomic_concepts_gradio/{filename}"
151
 
152
+ final_message = (
153
+ f"Successfully processed {len(question_list)} questions.\n"
154
+ f"Results saved to {filename} and pushed to repository.\n"
155
+ f"View results at: {file_url}"
156
+ )
157
+ if error_messages:
158
+ final_message += "\n\nErrors encountered:\n" + "\n".join(error_messages)
159
+ return final_message, filepath
160
 
161
+ except Exception as e:
162
+ raise Exception(f"Git operation failed: {str(e)}")
163
+ finally:
164
+ # Ensure cleanup happens even if there's an error
165
+ try:
166
+ shutil.rmtree(temp_dir)
167
+ except:
168
+ pass
169
+ try:
170
+ os.remove(key_file)
171
+ except:
172
+ pass
173
 
174
  except Exception as e:
175
  return f"Error pushing to repository: {str(e)}", None