You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload.py 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import hashlib
  2. import requests
  3. import os
  4. import random
  5. import json
  6. import time
  7. from tqdm import tqdm
  8. email = "liujd@lamda.nju.edu.cn"
  9. password = hashlib.md5(b"liujdlamda").hexdigest()
  10. login_url = "http://210.28.134.201:8089/auth/login"
  11. submit_url = "http://210.28.134.201:8089/user/add_learnware"
  12. all_data_type = ["Table", "Image", "Video", "Text", "Audio"]
  13. all_task_type = [
  14. "Classification",
  15. "Regression",
  16. "Clustering",
  17. "Feature Extraction",
  18. "Generation",
  19. "Segmentation",
  20. "Object Detection",
  21. ]
  22. all_device_type = ["CPU", "GPU"]
  23. all_scenario = [
  24. "Business",
  25. "Financial",
  26. "Health",
  27. "Politics",
  28. "Computer",
  29. "Internet",
  30. "Traffic",
  31. "Nature",
  32. "Fashion",
  33. "Industry",
  34. "Agriculture",
  35. "Education",
  36. "Entertainment",
  37. "Architecture",
  38. ]
  39. # ###############
  40. # 以上部分无需修改 #
  41. # ###############
  42. def main():
  43. session = requests.Session()
  44. res = session.post(login_url, json={"email": email, "password": password})
  45. # /path/to/learnware/folder 修改为学件文件夹地址
  46. learnware_pool = os.listdir(os.path.join(os.path.abspath("."), "learnware_pool"))
  47. for learnware in learnware_pool:
  48. # 修改相应的语义规约
  49. name = "PFS_Shop" + "%02d" % int(learnware.split(".")[0].split("_")[1])
  50. name = name + "_" + time.strftime("%Y%m%d%H%M%S", time.localtime())
  51. description = f"This is a description of learnware {name}"
  52. data = random.choice(all_data_type)
  53. task = random.choice(all_task_type)
  54. device = list(set(random.choices(all_device_type, k=2)))
  55. scenario = list(set(random.choices(all_scenario, k=5)))
  56. semantic_specification = {
  57. "Data": {"Values": ["Table"], "Type": "Class"},
  58. "Library": {"Values": ["Scikit-learn"], "Type": "Class"},
  59. "Task": {"Values": ["Regression"], "Type": "Class"},
  60. "Scenario": {"Values": ["Business"], "Type": "Tag"},
  61. "Description": {
  62. "Values": "A sales-forecasting model from Predict Future Sales Competition on Kaggle",
  63. "Type": "String",
  64. },
  65. "Name": {"Values": name, "Type": "String"},
  66. }
  67. res = session.post(
  68. submit_url,
  69. data={
  70. "semantic_specification": json.dumps(semantic_specification),
  71. },
  72. files={
  73. "learnware_file": open(
  74. os.path.join(os.path.abspath("."), "learnware_pool", learnware),
  75. "rb",
  76. )
  77. },
  78. )
  79. assert json.loads(res.text)["code"] == 0, "Upload error"
  80. if __name__ == "__main__":
  81. main()