Lenylvt commited on
Commit
a27b177
β€’
1 Parent(s): f4d47b0

Create SRT_Translation/API.md

Browse files
Files changed (1) hide show
  1. docs/SRT_Translation/API.md +76 -0
docs/SRT_Translation/API.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # API Documentation for `Lenylvt/SRT_Translation-API`
2
+
3
+ This documentation covers how to interact with the SRT_Translation API using both Python and JavaScript.
4
+
5
+ ## API Endpoint
6
+
7
+ To use this API, you can opt for the `gradio_client` Python library [docs](https://www.gradio.app/guides/getting-started-with-the-python-client) or the `@gradio/client` JavaScript package [docs](https://www.gradio.app/guides/getting-started-with-the-js-client).
8
+
9
+ ## Python Usage
10
+
11
+ ### Step 1: Installation
12
+
13
+ Firstly, 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
+ Locate the API endpoint for the function you wish to use. Replace the placeholder values in the snippet below with your actual input data. For accessing 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_Translation-API")
29
+ result = client.predict(
30
+ "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf", # filepath in 'Upload SRT File' File 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 `filepath` representing the output in the '*Translated SRT*' File component.
41
+
42
+ ## JavaScript Usage
43
+
44
+ ### Step 1: Installation
45
+
46
+ For JavaScript, ensure the `@gradio/client` package is installed 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, find the API endpoint that suits your needs. Replace the placeholders with your own data. If accessing a private Space, include your Hugging Face token.
55
+
56
+ **API Name**: `/predict`
57
+
58
+ ```javascript
59
+ import { client } from "@gradio/client";
60
+
61
+ const response_0 = await fetch("https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf");
62
+ const exampleFile = await response_0.blob();
63
+
64
+ const app = await client("Lenylvt/SRT_Translation-API");
65
+ const result = await app.predict("/predict", [
66
+ exampleFile, // blob in 'Upload SRT File' File component
67
+ "en", // string in 'Source Language' Dropdown component
68
+ "es", // string in 'Target Language' Dropdown component
69
+ ]);
70
+
71
+ console.log(result.data);
72
+ ```
73
+
74
+ **Return Type(s):**
75
+
76
+ - `undefined` representing the output in the '*Translated SRT*' File component.