Spaces:
Sleeping
Sleeping
Create SRT_to_Video/API.md
Browse files- docs/SRT_to_Video/API.md +84 -0
docs/SRT_to_Video/API.md
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# API Documentation for `Lenylvt/SRT_to_Video-API`
|
2 |
+
|
3 |
+
This documentation covers how to interact with the SRT_to_Video API using both Python and JavaScript.
|
4 |
+
|
5 |
+
## API Endpoint
|
6 |
+
|
7 |
+
To use this API, you can choose between the `gradio_client` Python library [docs](https://www.gradio.app/guides/getting-started-with-the-python-client) or the `@gradio/client` JavaScript package [doc](https://www.gradio.app/guides/getting-started-with-the-js-client).
|
8 |
+
|
9 |
+
## Python Usage
|
10 |
+
|
11 |
+
### Step 1: Installation
|
12 |
+
|
13 |
+
First, install the `gradio_client` if it's not already installed.
|
14 |
+
|
15 |
+
```python
|
16 |
+
pip install gradio_client
|
17 |
+
```
|
18 |
+
|
19 |
+
### Step 2: Making a Request
|
20 |
+
|
21 |
+
Find the API endpoint for the function you want to use. Replace the placeholder values in the snippet below with your input data. For private Spaces, you might need to include your Hugging Face token as well.
|
22 |
+
|
23 |
+
**API Name**: `/predict`
|
24 |
+
|
25 |
+
```python
|
26 |
+
from gradio_client import Client
|
27 |
+
|
28 |
+
client = Client("Lenylvt/SRT_to_Video-API")
|
29 |
+
result = client.predict(
|
30 |
+
{
|
31 |
+
"video": "https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4",
|
32 |
+
"subtitles": None
|
33 |
+
}, # Dict(video: filepath, subtitles: filepath | None) in 'Video' Video component
|
34 |
+
"https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf", # filepath in 'Subtitle' File component
|
35 |
+
"Hard", # Literal['Hard', 'Soft'] in 'Subtitle Type' Radio component
|
36 |
+
"en", # str in 'Subtitle Language (ISO 639-1 code, e.g., 'en' for English)' Textbox component
|
37 |
+
api_name="/predict"
|
38 |
+
)
|
39 |
+
print(result)
|
40 |
+
```
|
41 |
+
|
42 |
+
**Return Type(s):**
|
43 |
+
|
44 |
+
- A `Dict(video: filepath, subtitles: filepath | None)` representing the output in the '*Processed Video*' Video component.
|
45 |
+
|
46 |
+
## JavaScript Usage
|
47 |
+
|
48 |
+
### Step 1: Installation
|
49 |
+
|
50 |
+
For JavaScript, install the `@gradio/client` package if it's not already present in your project.
|
51 |
+
|
52 |
+
```bash
|
53 |
+
npm i -D @gradio/client
|
54 |
+
```
|
55 |
+
|
56 |
+
### Step 2: Making a Request
|
57 |
+
|
58 |
+
Similar to Python, find the API endpoint that matches your desired function. Replace the placeholders with your own data. Include your Hugging Face token for private Spaces.
|
59 |
+
|
60 |
+
**API Name**: `/predict`
|
61 |
+
|
62 |
+
```javascript
|
63 |
+
import { client } from "@gradio/client";
|
64 |
+
|
65 |
+
const response_0 = await fetch("[object Object]");
|
66 |
+
const exampleVideo = await response_0.blob();
|
67 |
+
|
68 |
+
const response_1 = await fetch("https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf");
|
69 |
+
const exampleFile = await response_1.blob();
|
70 |
+
|
71 |
+
const app = await client("Lenylvt/SRT_to_Video-API");
|
72 |
+
const result = await app.predict("/predict", [
|
73 |
+
exampleVideo, // blob in 'Video' Video component
|
74 |
+
exampleFile, // blob in 'Subtitle' File component
|
75 |
+
"Hard", // string in 'Subtitle Type' Radio component
|
76 |
+
"en", // string in 'Subtitle Language (ISO 639-1 code, e.g., 'en' for English)' Textbox component
|
77 |
+
]);
|
78 |
+
|
79 |
+
console.log(result.data);
|
80 |
+
```
|
81 |
+
|
82 |
+
**Return Type(s):**
|
83 |
+
|
84 |
+
- `undefined` representing the output in the '*Processed Video*' Video component.
|