Restore and activate the Kaggle credentials bootstrap function in app.py
Browse files- .gitignore +0 -1
- app.py +14 -14
.gitignore
CHANGED
@@ -1,3 +1,2 @@
|
|
1 |
.env
|
2 |
.mcp-venv/
|
3 |
-
.gradio
|
|
|
1 |
.env
|
2 |
.mcp-venv/
|
|
app.py
CHANGED
@@ -71,21 +71,21 @@ demo = gr.TabbedInterface(
|
|
71 |
tab_names=["Search", "Files", "Download"]
|
72 |
)
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
|
88 |
-
|
89 |
|
90 |
api = KaggleApi()
|
91 |
api.authenticate()
|
|
|
71 |
tab_names=["Search", "Files", "Download"]
|
72 |
)
|
73 |
|
74 |
+
def _bootstrap_kaggle_credentials():
|
75 |
+
user = os.getenv("KAGGLE_USERNAME")
|
76 |
+
key = os.getenv("KAGGLE_KEY")
|
77 |
+
if not (user and key):
|
78 |
+
raise RuntimeError(
|
79 |
+
"Kaggle credentials not found."
|
80 |
+
"Set KAGGLE_USERNAME and KAGGLE_KEY as env vars or in .env"
|
81 |
+
)
|
82 |
+
cred_path = pathlib.Path.home() / ".kaggle" / "kaggle.json"
|
83 |
+
if not cred_path.exists():
|
84 |
+
cred_path.parent.mkdir(exist_ok=True)
|
85 |
+
cred_path.write_text(json.dumps({"username": user, "key": key}))
|
86 |
+
cred_path.chmod(0o600)
|
87 |
|
88 |
+
_bootstrap_kaggle_credentials()
|
89 |
|
90 |
api = KaggleApi()
|
91 |
api.authenticate()
|