broadfield commited on
Commit
409e43f
·
verified ·
1 Parent(s): bde8b17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -174,7 +174,7 @@ def parse_json(inp):
174
  return out1,out2
175
  def build_space(repo_name,file_name,file_content,access_token=""):
176
  try:
177
- repo_path="community-pool/"+repo_name
178
  if not access_token:access_token=os.environ['HF_TOKEN']
179
 
180
  api=HfApi(endpoint="https://huggingface.co", token=access_token)
@@ -197,12 +197,12 @@ def build_space(repo_name,file_name,file_content,access_token=""):
197
  f.write(str(file_content))
198
  f.close()
199
  # Upload a local file to the Space
200
- commit_message = "Adding file test: "+str(uuid.uuid4())
201
 
202
  api.upload_file(path_or_fileobj=local_file_path, path_in_repo=file_name, repo_id=repo_path, repo_type='space', commit_message=commit_message)
203
  print("File uploaded successfully.")
204
  # Commit changes
205
- commit_message += "\nInitial commit to the repository."+ local_file_path
206
  #api.commit_repo(space_id, message=commit_message)
207
  return [{'role':'assistant','content': commit_message+'\nCommit Success' }]
208
  except Exception as e:
@@ -261,6 +261,8 @@ def agent(prompt_in,history,mod=2):
261
  out_o =generate(prompt,history,mod=mod,tok=10000,seed=seed,role="CREATE_FILE",data=in_data)
262
  out_w=list(out_o)
263
  ret1,ret2 = parse_json(out_w[2].split('<|im_end|>')[0])
 
 
264
  build_out = build_space('test1',ret1,ret2)
265
  history+=[{'role':'system','content':f'observation:{build_out}'}]
266
  yield history
 
174
  return out1,out2
175
  def build_space(repo_name,file_name,file_content,access_token=""):
176
  try:
177
+ repo_path="community-pool/"+str(repo_name)
178
  if not access_token:access_token=os.environ['HF_TOKEN']
179
 
180
  api=HfApi(endpoint="https://huggingface.co", token=access_token)
 
197
  f.write(str(file_content))
198
  f.close()
199
  # Upload a local file to the Space
200
+ commit_message = "Adding file test: "+ str(file_name)
201
 
202
  api.upload_file(path_or_fileobj=local_file_path, path_in_repo=file_name, repo_id=repo_path, repo_type='space', commit_message=commit_message)
203
  print("File uploaded successfully.")
204
  # Commit changes
205
+ commit_message += "\nInitial commit to the repository."+ f'{repo_path}/' + f'{file_name}'
206
  #api.commit_repo(space_id, message=commit_message)
207
  return [{'role':'assistant','content': commit_message+'\nCommit Success' }]
208
  except Exception as e:
 
261
  out_o =generate(prompt,history,mod=mod,tok=10000,seed=seed,role="CREATE_FILE",data=in_data)
262
  out_w=list(out_o)
263
  ret1,ret2 = parse_json(out_w[2].split('<|im_end|>')[0])
264
+ print('ret1',ret1)
265
+ print('ret2',ret2)
266
  build_out = build_space('test1',ret1,ret2)
267
  history+=[{'role':'system','content':f'observation:{build_out}'}]
268
  yield history