morpheuslord commited on
Commit
7336080
Β·
1 Parent(s): f5753b4

Add training pipeline

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +0 -1
app.py CHANGED
@@ -4,6 +4,46 @@ Runs train_and_upgrade.py in the background, streams logs live,
4
  and exports the upgraded model to morpheuslord/rewrite on completion.
5
  """
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  import gradio as gr
8
  import subprocess
9
  import threading
 
4
  and exports the upgraded model to morpheuslord/rewrite on completion.
5
  """
6
 
7
+ # ── Compatibility patch ───────────────────────────────────────────────────────
8
+ # HF Spaces forces gradio 4.44.0 which imports HfFolder from huggingface_hub.
9
+ # huggingface_hub >= 0.30 removed HfFolder. Patch it back before gradio loads.
10
+ try:
11
+ from huggingface_hub import HfFolder # noqa: F401 -- check if it exists
12
+ except ImportError:
13
+ import os as _os
14
+ import huggingface_hub as _hfhub
15
+ from huggingface_hub import constants as _hfconst
16
+
17
+ class HfFolder:
18
+ path_token = _hfconst.HF_TOKEN_PATH
19
+
20
+ @classmethod
21
+ def get_token(cls):
22
+ env = _os.environ.get("HF_TOKEN") or _os.environ.get("HUGGING_FACE_HUB_TOKEN")
23
+ if env:
24
+ return env
25
+ try:
26
+ with open(cls.path_token) as f:
27
+ return f.read().strip() or None
28
+ except Exception:
29
+ return None
30
+
31
+ @classmethod
32
+ def save_token(cls, token):
33
+ _os.makedirs(_os.path.dirname(cls.path_token), exist_ok=True)
34
+ with open(cls.path_token, "w") as f:
35
+ f.write(token)
36
+
37
+ @classmethod
38
+ def delete_token(cls):
39
+ try:
40
+ _os.remove(cls.path_token)
41
+ except FileNotFoundError:
42
+ pass
43
+
44
+ _hfhub.HfFolder = HfFolder
45
+ # ─────────────────────────────────────────────────────────────────────────────
46
+
47
  import gradio as gr
48
  import subprocess
49
  import threading
requirements.txt CHANGED
@@ -10,4 +10,3 @@ sentencepiece>=0.1.99
10
  huggingface_hub>=0.30.0
11
  nltk>=3.8.0
12
  numpy>=1.26.0
13
- gradio==5.29.0
 
10
  huggingface_hub>=0.30.0
11
  nltk>=3.8.0
12
  numpy>=1.26.0