Spaces:
Runtime error
Runtime error
Charlie
commited on
Commit
·
84f514d
1
Parent(s):
c433511
update files
Browse files- dist/main.js +18 -2
- index.html +3 -0
- src/main.ts +24 -3
- styles/main.css +5 -0
dist/main.js
CHANGED
|
@@ -299,7 +299,7 @@ async function getOrganizationInfo(accessToken) {
|
|
| 299 |
}
|
| 300 |
return response.json();
|
| 301 |
}
|
| 302 |
-
async function createRepository(accessToken, name) {
|
| 303 |
const response = await fetch("https://huggingface.co/api/repos/create", {
|
| 304 |
method: "POST",
|
| 305 |
headers: {
|
|
@@ -309,6 +309,7 @@ async function createRepository(accessToken, name) {
|
|
| 309 |
body: JSON.stringify({
|
| 310 |
type: "model",
|
| 311 |
name,
|
|
|
|
| 312 |
private: false
|
| 313 |
})
|
| 314 |
});
|
|
@@ -334,9 +335,13 @@ var init = async () => {
|
|
| 334 |
if (createRepoButton && repoNameInput) {
|
| 335 |
createRepoButton.onclick = async () => {
|
| 336 |
const repoName = repoNameInput.value.trim();
|
|
|
|
|
|
|
|
|
|
| 337 |
if (repoName) {
|
| 338 |
try {
|
| 339 |
-
|
|
|
|
| 340 |
repoNameInput.value = "";
|
| 341 |
alert("Repository created successfully!");
|
| 342 |
} catch (error) {
|
|
@@ -348,6 +353,17 @@ var init = async () => {
|
|
| 348 |
}
|
| 349 |
try {
|
| 350 |
const orgInfo = await getOrganizationInfo(accessToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
const preElement = document.querySelector("pre");
|
| 352 |
if (preElement) {
|
| 353 |
preElement.textContent = JSON.stringify(
|
|
|
|
| 299 |
}
|
| 300 |
return response.json();
|
| 301 |
}
|
| 302 |
+
async function createRepository(accessToken, name, organization) {
|
| 303 |
const response = await fetch("https://huggingface.co/api/repos/create", {
|
| 304 |
method: "POST",
|
| 305 |
headers: {
|
|
|
|
| 309 |
body: JSON.stringify({
|
| 310 |
type: "model",
|
| 311 |
name,
|
| 312 |
+
organization,
|
| 313 |
private: false
|
| 314 |
})
|
| 315 |
});
|
|
|
|
| 335 |
if (createRepoButton && repoNameInput) {
|
| 336 |
createRepoButton.onclick = async () => {
|
| 337 |
const repoName = repoNameInput.value.trim();
|
| 338 |
+
const orgSelect = document.getElementById(
|
| 339 |
+
"org-select"
|
| 340 |
+
);
|
| 341 |
if (repoName) {
|
| 342 |
try {
|
| 343 |
+
const selectedOrg = orgSelect?.value || void 0;
|
| 344 |
+
await createRepository(accessToken, repoName, selectedOrg);
|
| 345 |
repoNameInput.value = "";
|
| 346 |
alert("Repository created successfully!");
|
| 347 |
} catch (error) {
|
|
|
|
| 353 |
}
|
| 354 |
try {
|
| 355 |
const orgInfo = await getOrganizationInfo(accessToken);
|
| 356 |
+
const orgSelect = document.getElementById(
|
| 357 |
+
"org-select"
|
| 358 |
+
);
|
| 359 |
+
if (orgSelect && orgInfo.organizations) {
|
| 360 |
+
orgInfo.organizations.forEach((org) => {
|
| 361 |
+
const option = document.createElement("option");
|
| 362 |
+
option.value = org.name;
|
| 363 |
+
option.textContent = org.name;
|
| 364 |
+
orgSelect.appendChild(option);
|
| 365 |
+
});
|
| 366 |
+
}
|
| 367 |
const preElement = document.querySelector("pre");
|
| 368 |
if (preElement) {
|
| 369 |
preElement.textContent = JSON.stringify(
|
index.html
CHANGED
|
@@ -16,6 +16,9 @@
|
|
| 16 |
<button id="signout" style="display: none;" class="auth-button">Sign out</button>
|
| 17 |
</div>
|
| 18 |
<div id="repo-form" style="display: none;" class="repo-form">
|
|
|
|
|
|
|
|
|
|
| 19 |
<input type="text" id="repo-name" placeholder="Enter repository name" class="repo-input">
|
| 20 |
<button id="create-repo" class="repo-button">Create Repository</button>
|
| 21 |
</div>
|
|
|
|
| 16 |
<button id="signout" style="display: none;" class="auth-button">Sign out</button>
|
| 17 |
</div>
|
| 18 |
<div id="repo-form" style="display: none;" class="repo-form">
|
| 19 |
+
<select id="org-select" class="repo-input">
|
| 20 |
+
<option value="">Personal Account</option>
|
| 21 |
+
</select>
|
| 22 |
<input type="text" id="repo-name" placeholder="Enter repository name" class="repo-input">
|
| 23 |
<button id="create-repo" class="repo-button">Create Repository</button>
|
| 24 |
</div>
|
src/main.ts
CHANGED
|
@@ -41,7 +41,8 @@ async function getOrganizationInfo(
|
|
| 41 |
|
| 42 |
async function createRepository(
|
| 43 |
accessToken: string,
|
| 44 |
-
name: string
|
|
|
|
| 45 |
): Promise<void> {
|
| 46 |
const response = await fetch("https://huggingface.co/api/repos/create", {
|
| 47 |
method: "POST",
|
|
@@ -52,6 +53,7 @@ async function createRepository(
|
|
| 52 |
body: JSON.stringify({
|
| 53 |
type: "model",
|
| 54 |
name: name,
|
|
|
|
| 55 |
private: false,
|
| 56 |
}),
|
| 57 |
});
|
|
@@ -84,9 +86,13 @@ const init = async (): Promise<void> => {
|
|
| 84 |
if (createRepoButton && repoNameInput) {
|
| 85 |
createRepoButton.onclick = async () => {
|
| 86 |
const repoName = repoNameInput.value.trim();
|
|
|
|
|
|
|
|
|
|
| 87 |
if (repoName) {
|
| 88 |
try {
|
| 89 |
-
|
|
|
|
| 90 |
repoNameInput.value = ""; // Clear input after success
|
| 91 |
alert("Repository created successfully!");
|
| 92 |
} catch (error) {
|
|
@@ -97,9 +103,24 @@ const init = async (): Promise<void> => {
|
|
| 97 |
};
|
| 98 |
}
|
| 99 |
|
| 100 |
-
// Get organization info after successful authentication
|
| 101 |
try {
|
| 102 |
const orgInfo = await getOrganizationInfo(accessToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
const preElement = document.querySelector("pre");
|
| 104 |
if (preElement) {
|
| 105 |
preElement.textContent = JSON.stringify(
|
|
|
|
| 41 |
|
| 42 |
async function createRepository(
|
| 43 |
accessToken: string,
|
| 44 |
+
name: string,
|
| 45 |
+
organization?: string
|
| 46 |
): Promise<void> {
|
| 47 |
const response = await fetch("https://huggingface.co/api/repos/create", {
|
| 48 |
method: "POST",
|
|
|
|
| 53 |
body: JSON.stringify({
|
| 54 |
type: "model",
|
| 55 |
name: name,
|
| 56 |
+
organization: organization,
|
| 57 |
private: false,
|
| 58 |
}),
|
| 59 |
});
|
|
|
|
| 86 |
if (createRepoButton && repoNameInput) {
|
| 87 |
createRepoButton.onclick = async () => {
|
| 88 |
const repoName = repoNameInput.value.trim();
|
| 89 |
+
const orgSelect = document.getElementById(
|
| 90 |
+
"org-select"
|
| 91 |
+
) as HTMLSelectElement;
|
| 92 |
if (repoName) {
|
| 93 |
try {
|
| 94 |
+
const selectedOrg = orgSelect?.value || undefined;
|
| 95 |
+
await createRepository(accessToken, repoName, selectedOrg);
|
| 96 |
repoNameInput.value = ""; // Clear input after success
|
| 97 |
alert("Repository created successfully!");
|
| 98 |
} catch (error) {
|
|
|
|
| 103 |
};
|
| 104 |
}
|
| 105 |
|
| 106 |
+
// Get organization info and populate org select after successful authentication
|
| 107 |
try {
|
| 108 |
const orgInfo = await getOrganizationInfo(accessToken);
|
| 109 |
+
|
| 110 |
+
// Populate org select
|
| 111 |
+
const orgSelect = document.getElementById(
|
| 112 |
+
"org-select"
|
| 113 |
+
) as HTMLSelectElement;
|
| 114 |
+
if (orgSelect && orgInfo.organizations) {
|
| 115 |
+
orgInfo.organizations.forEach((org) => {
|
| 116 |
+
const option = document.createElement("option");
|
| 117 |
+
option.value = org.name;
|
| 118 |
+
option.textContent = org.name;
|
| 119 |
+
orgSelect.appendChild(option);
|
| 120 |
+
});
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Display full info in pre element
|
| 124 |
const preElement = document.querySelector("pre");
|
| 125 |
if (preElement) {
|
| 126 |
preElement.textContent = JSON.stringify(
|
styles/main.css
CHANGED
|
@@ -53,9 +53,14 @@ h2 {
|
|
| 53 |
margin: 2rem auto;
|
| 54 |
max-width: 400px;
|
| 55 |
display: flex;
|
|
|
|
| 56 |
gap: 1rem;
|
| 57 |
}
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
.repo-input {
|
| 60 |
flex: 1;
|
| 61 |
padding: 0.8rem;
|
|
|
|
| 53 |
margin: 2rem auto;
|
| 54 |
max-width: 400px;
|
| 55 |
display: flex;
|
| 56 |
+
flex-wrap: wrap;
|
| 57 |
gap: 1rem;
|
| 58 |
}
|
| 59 |
|
| 60 |
+
.repo-form select.repo-input {
|
| 61 |
+
min-width: 200px;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
.repo-input {
|
| 65 |
flex: 1;
|
| 66 |
padding: 0.8rem;
|