Spaces:
Sleeping
Sleeping
Create Translator/API.md
Browse files- docs/Translator/API.md +73 -0
docs/Translator/API.md
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# API Documentation for `Lenylvt/Translator-API`
|
2 |
+
|
3 |
+
This documentation explains how to interact with the Translator API using both Python and JavaScript.
|
4 |
+
|
5 |
+
## API Endpoint
|
6 |
+
|
7 |
+
To interact with this API, you have the option to use the `gradio_client` Python library or the `@gradio/client` JavaScript package.
|
8 |
+
|
9 |
+
## Python Usage
|
10 |
+
|
11 |
+
### Step 1: Installation
|
12 |
+
|
13 |
+
First, install the `gradio_client` library if it's not already installed.
|
14 |
+
|
15 |
+
```python
|
16 |
+
pip install gradio_client
|
17 |
+
```
|
18 |
+
|
19 |
+
### Step 2: Making a Request
|
20 |
+
|
21 |
+
Locate the API endpoint for the function you intend to use. Replace the placeholder values in the snippet below with your actual input data. If accessing a private Space, you may need to include your Hugging Face token.
|
22 |
+
|
23 |
+
**API Name**: `/predict`
|
24 |
+
|
25 |
+
```python
|
26 |
+
from gradio_client import Client
|
27 |
+
|
28 |
+
client = Client("Lenylvt/Translator-API")
|
29 |
+
result = client.predict(
|
30 |
+
"Hello!!", # str in 'text' Textbox component
|
31 |
+
"en", # Source Language (ISO 639-1 code, e.g., 'en' for English) in 'Source Language' Dropdown component
|
32 |
+
"es", # Target Language (ISO 639-1 code, e.g., 'es' for Spanish) in 'Target Language' Dropdown component
|
33 |
+
api_name="/predict"
|
34 |
+
)
|
35 |
+
print(result)
|
36 |
+
```
|
37 |
+
|
38 |
+
**Return Type(s):**
|
39 |
+
|
40 |
+
- A `str` representing the translated text output in the 'output' Textbox component.
|
41 |
+
|
42 |
+
## JavaScript Usage
|
43 |
+
|
44 |
+
### Step 1: Installation
|
45 |
+
|
46 |
+
Install the `@gradio/client` package if it's not already in your project.
|
47 |
+
|
48 |
+
```bash
|
49 |
+
npm i -D @gradio/client
|
50 |
+
```
|
51 |
+
|
52 |
+
### Step 2: Making a Request
|
53 |
+
|
54 |
+
As with Python, identify the API endpoint that matches your requirement. Replace the placeholders with your data. If this is a private Space, don't forget to include your Hugging Face token.
|
55 |
+
|
56 |
+
**API Name**: `/predict`
|
57 |
+
|
58 |
+
```javascript
|
59 |
+
import { client } from "@gradio/client";
|
60 |
+
|
61 |
+
const app = await client("Lenylvt/Translator-API");
|
62 |
+
const result = await app.predict("/predict", [
|
63 |
+
"Hello!!", // string in 'text' Textbox component
|
64 |
+
"en", // string representing ISO 639-1 code for Source Language in 'Source Language' Dropdown component
|
65 |
+
"es", // string representing ISO 639-1 code for Target Language in 'Target Language' Dropdown component
|
66 |
+
]);
|
67 |
+
|
68 |
+
console.log(result.data);
|
69 |
+
```
|
70 |
+
|
71 |
+
**Return Type(s):**
|
72 |
+
|
73 |
+
- A `string` representing the translated text output in the 'output' Textbox component.
|