Commit 7478c6ee authored by duanjinfei's avatar duanjinfei

update document

parent 91d4c75f
--- ---
title: Bark API Usage Guide title: Bark API Usage Guide
slug: 6DCWoM_fbbp1XuSHH8vVc slug: 6DCWoM_fbbp1XuSHH8vVV
createdAt: Thu Jul 18 2024 06:12:37 GMT+0000 (Coordinated Universal Time) createdAt: Thu Jul 18 2024 06:12:37 GMT+0000 (Coordinated Universal Time)
updatedAt: Thu Jul 18 2024 13:40:04 GMT+0000 (Coordinated Universal Time) updatedAt: Thu Jul 18 2024 13:40:04 GMT+0000 (Coordinated Universal Time)
--- ---
......
--- ---
title: Co de API Usage Guide title: Codeformer API Usage Guide
createdAt: Thu Jul 18 2024 06:12:37 GMT+0000 (Coordinated Universal Time) createdAt: Thu Jul 18 2024 06:12:37 GMT+0000 (Coordinated Universal Time)
updatedAt: Thu Jul 18 2024 13:40:04 GMT+0000 (Coordinated Universal Time) updatedAt: Thu Jul 18 2024 13:40:04 GMT+0000 (Coordinated Universal Time)
--- ---
......
---
title: DreamBooth API Usage Guide
createdAt: Thu Jul 18 2024 06:12:37 GMT+0000 (Coordinated Universal Time)
updatedAt: Thu Jul 18 2024 13:40:04 GMT+0000 (Coordinated Universal Time)
---
# DreamBooth API Usage Guide
## Introduction
This document will guide developers on how to use the aonweb library to call the DreamBooth API, which is used for voice cloning and text-to-speech conversion.
## Prerequisites
- Node.js environment
- `aonweb` library installed
- Valid Aonet APPID
## Basic Usage
### 1. Import Required Modules
```js
import { AI, AIOptions } from 'aonweb';
```
### 2. Initialize AI Instance
```js
const ai_options = new AIOptions({
appId: 'your_app_id_here',
dev_mode: true
});
const aonweb = new AI(ai_options);
```
### 3. Prepare Input Data Example
```js
const data = {
input:{
"seed": 1337,
"adam_beta1": 0.9,
"adam_beta2": 0.999,
"resolution": 512,
"adam_epsilon": 1e-8,
"class_prompt": "a cat",
"lr_scheduler": "constant",
"instance_data": "https://replicate.delivery/pbxt/HlRmIY3SePK6D8ZgnTvgymRWRSFqJlrDrfxJjA6QAazg1wVl/data.zip",
"learning_rate": 0.000001,
"max_grad_norm": 1,
"n_save_sample": 4,
"use_8bit_adam": false,
"instance_prompt": "a cjw cat",
"max_train_steps": 1000,
"num_class_images": 100,
"num_train_epochs": 1,
"save_infer_steps": 50,
"train_batch_size": 1,
"adam_weight_decay": 0.01,
"prior_loss_weight": 1,
"sample_batch_size": 4,
"train_text_encoder": true,
"save_guidance_scale": 7.5,
"gradient_checkpointing": false,
"with_prior_preservation": true,
"gradient_accumulation_steps": 1
}
};
```
### 4. Call the AI Model
```js
const price = 8; // Cost of the AI call
try {
const response = await aonweb.prediction("/predictions/ai/dreambooth", data, price);
// Handle response
console.log("DreamBooth result:", response);
} catch (error) {
// Error handling
console.error("Error generating :", error);
}
```
### Parameter Description
-
### Notes
- Ensure that the provided audio URL is publicly accessible and of good quality to achieve the best cloning effect.
- The API may take some time to process the input and generate the result, consider implementing appropriate wait or loading states.
- Handle possible errors, such as network issues, invalid input, or API limitations.
- Adhere to the terms of use and privacy regulations, especially when handling voice samples of others.
### Example Response
The API response will contain the URL of the generated cloned voice or other relevant information. Parse and use the response data according to the actual API documentation.
\ No newline at end of file
...@@ -54,7 +54,7 @@ const data = { ...@@ -54,7 +54,7 @@ const data = {
```js ```js
const price = 8; // Cost of the AI call const price = 8; // Cost of the AI call
try { try {
const response = await aonweb.prediction("/predictions/ai/xtts-V2", data, price); const response = await aonweb.prediction("/predictions/ai/xtts-v2", data, price);
// Handle response // Handle response
console.log("XTTS-V2 result:", response); console.log("XTTS-V2 result:", response);
} catch (error) { } catch (error) {
......
...@@ -20,7 +20,7 @@ The `onOversize` function checks if the uploaded file exceeds the maximum allowe ...@@ -20,7 +20,7 @@ The `onOversize` function checks if the uploaded file exceeds the maximum allowe
```javascript ```javascript
const onOversize = (file) => { const onOversize = (file) => {
showToast('The file size cannot exceed 30MB'); console.log('The file size cannot exceed 30MB');
}; };
``` ```
......
---
sidebar_position: 3
title: User Account and Points Retrieval
slug: FPVY464Iqc2ZCl1pANyS0
createdAt: Thu Jul 18 2024 05:56:40 GMT+0000 (Coordinated Universal Time)
updatedAt: Fri Jul 19 2024 03:50:33 GMT+0000 (Coordinated Universal Time)
---
# Get User Account Function
This documentation provides a detailed explanation of the `getAccount` function, which handles user account retrieval, login authentication, and interaction with the Ethereum provider. It includes asynchronous operations to ensure smooth and non-blocking user experience.
## Function: `getAccount`
### Description
The `getAccount` function checks if a user is logged in. If not, it initiates the login process. Once the user is logged in, it retrieves the user's Ethereum account. The function also handles loading indicators and emits events upon successful account retrieval.
### Code
```javascript
async function getAccount() {
try {
// Create a new User instance
let user = new User();
// Check if the user is logged in
const isLogin_status = await user.islogin();
console.log(isLogin_status, 'isLogin_status');
if (!isLogin_status) {
// Show loading indicator if the user is not logged in
showLoadingToast({
duration: 0,
forbidClick: true,
message: 'Loading...',
});
// Initiate login process
user.login((acc, userId, error) => {
// Close loading indicator
closeToast();
console.log("getWeb3 account", acc);
console.log("getWeb3 userId", userId);
console.log("getWeb3 error", error);
// Set the account value and emit event upon successful login
account.value = acc;
bus.emit('get_balance', "login");
});
} else {
// If user is already logged in, interact with Ethereum provider to get account
let account = await user.getAccount();
console.log("getWeb3 account", account);
let userId = await user.getUserId();
console.log("getWeb3 userId", userId);
account.value = account;
// Emit event after retrieving the account
bus.emit('get_balance', "login");
}
} catch (error) {
// Close loading indicator and handle errors
closeToast();
console.log(error, "getAccount error");
if (error && typeof error == 'string') {
showToast(error);
} else {
showToast(error.message);
}
} finally {
// Final clean-up actions if needed
}
}
```
### Detailed Explanation
1. **User Object Initialization:**
- Creates a new instance of the `User` object.
2. **Check Login Status:**
- Asynchronously checks if the user is logged in.
- Logs the login status.
3. **Handle Not Logged In Status:**
- Shows a loading toast if the user is not logged in.
4. **User Login Process:**
- Initiates the login process.
- Closes the loading toast upon completion.
- Logs the account, userId, and any error.
- Sets the account value and emits an event upon successful login.
5. **Handle Logged In Status:**
- Interacts with the Ethereum provider to get the account if the user is already logged in.
- Sets the account value and emits an event after retrieving the account.
6. **Error Handling:**
- Closes the loading toast in case of an error.
- Logs the error.
- Shows an appropriate error message to the user.
### Usage in Component Lifecycle
The `getAccount` function can be called within the component's lifecycle hooks to ensure that the user's account is retrieved and logged in status is checked when necessary.
### Example Usage
```javascript
onMounted(() => {
getAccount();
});
```
This setup ensures that the user account status is checked and handled as soon as the component is ready, providing a seamless experience for the user.
...@@ -21,18 +21,10 @@ The `login` function is designed to check if a user is logged in, and if not, it ...@@ -21,18 +21,10 @@ The `login` function is designed to check if a user is logged in, and if not, it
```javascript ```javascript
async function login() { async function login() {
try { try {
let time = new Date().getTime();
console.log(`demo index login start time = ${time}`);
let user = new User(); let user = new User();
let temp = await user.islogin(); let temp = await user.islogin();
console.log(`demo index islogin end time = ${time}, temp = ${temp}`);
if (!temp) { if (!temp) {
showLoadingToast({
duration: 0,
forbidClick: true,
message: 'Loading...',
});
console.log(`demo index showLoadingToast end time = ${time}`);
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
let result = await user.getOwnedUsers(); let result = await user.getOwnedUsers();
let userid = result && result._userIds && result._userIds.length && result._userIds[0]; let userid = result && result._userIds && result._userIds.length && result._userIds[0];
...@@ -41,68 +33,36 @@ async function login() { ...@@ -41,68 +33,36 @@ async function login() {
} }
await sleep(300); await sleep(300);
} }
closeToast();
temp = await user.islogin(); temp = await user.islogin();
if (!temp) { if (!temp) {
showToast("login failed, please try again later"); console.log("login failed, please try again later");
return; return;
} }
} }
bus.emit('get_balance', "login");
console.log(`demo index login end time = ${new Date().getTime() - time}`);
} catch (error) { } catch (error) {
console.log("index demo error", error); console.log("index demo error", error);
closeToast();
if (error && typeof error == 'string') { if (error && typeof error == 'string') {
showToast(error); console.log(error);
} else { } else {
showToast(error.message); console.log(error.message);
} }
} finally {
} }
} }
onMounted(() => {
getTemplateList();
login();
});
``` ```
### Detailed Explanation ### Detailed Explanation
1. **Initialization and Logging Start Time:** 1. **User Object and Initial Login Check:**
- Records the start time for login.
- Logs the start time to the console.
2. **User Object and Initial Login Check:**
- Creates a new `User` object. - Creates a new `User` object.
- Checks if the user is already logged in by calling `user.islogin()` and logs the result. - Checks if the user is already logged in by calling `user.islogin()` and logs the result.
3. **Show Loading Indicator:** 2. **Repeated Attempts to Get Owned Users:**
- If the user is not logged in, shows a loading toast to inform the user that a login attempt is in progress.
4. **Repeated Attempts to Get Owned Users:**
- Attempts to get the list of owned users up to 5 times, with a 300ms delay between each attempt. - Attempts to get the list of owned users up to 5 times, with a 300ms delay between each attempt.
- Breaks the loop if a valid user ID is found. - Breaks the loop if a valid user ID is found.
5. **Close Toast and Final Login Check:** 3. **Error Handling:**
- Closes the loading toast.
- Checks the login status again. If still not logged in, shows an error toast and exits the function.
6. **Emit Event and Log End Time:**
- Emits an event to get the balance.
- Logs the end time to the console.
7. **Error Handling:**
- Catches any errors that occur during the login process. - Catches any errors that occur during the login process.
- Logs the error to the console. - Logs the error to the console.
- Closes the toast and shows an appropriate error message to the user. - Closes the toast and shows an appropriate error message to the user.
## Usage in Component Lifecycle
The `login` function is called within the `onMounted` lifecycle hook, ensuring that the login process is initiated when the component is mounted.
```javascript
onMounted(() => {
login();
});
```
- `getTemplateList()`: Fetches the list of templates (additional context not provided in the snippet).
- `login()`: Initiates the login process.
This setup ensures that the user login status is checked and handled as soon as the component is ready, providing a seamless experience for the user. This setup ensures that the user login status is checked and handled as soon as the component is ready, providing a seamless experience for the user.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment