ttttdiva commited on
Commit
e17e2d6
·
verified ·
1 Parent(s): cc284f2

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +29 -0
main.py CHANGED
@@ -48,6 +48,35 @@ class Config:
48
  # 暗号化されたファイルが出力されるローカルディレクトリ(cryptLocal: の実体)
49
  ENCRYPTED_DIR = "/home/user/app/encrypted"
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # =============================================================================
53
  # rclone まわり
 
48
  # 暗号化されたファイルが出力されるローカルディレクトリ(cryptLocal: の実体)
49
  ENCRYPTED_DIR = "/home/user/app/encrypted"
50
 
51
+ class CivitAICrawler:
52
+ """CivitAIからモデルをダウンロードし、Hugging Faceにアップロードするクラス(フォルダ名も暗号化対応版)"""
53
+
54
+ def __init__(self, config: Config):
55
+ self.config = config
56
+ self.api = HfApi()
57
+ self.app = FastAPI()
58
+ self.repo_ids = self.config.REPO_IDS.copy()
59
+ self.jst = self.config.JST
60
+
61
+ # rclone のセットアップ(rclone.conf を環境変数から生成)
62
+ self.setup_rclone_conf()
63
+
64
+ self.setup_routes()
65
+
66
+ def setup_routes(self):
67
+ @self.app.get("/")
68
+ def read_root():
69
+ now = str(datetime.datetime.now(self.jst))
70
+ description = f"""
71
+ CivitAIを定期的に周回し新規モデルを {self.repo_ids['current']} にバックアップするSpaceです。
72
+ 詳細は https://huggingface.co/{self.repo_ids['model_list']}/blob/main/model_list.log からどうぞ。
73
+ Status: {now} + currently running :D
74
+ """
75
+ return description
76
+
77
+ @self.app.on_event("startup")
78
+ async def startup_event():
79
+ asyncio.create_task(self.crawl())
80
 
81
  # =============================================================================
82
  # rclone まわり