Documentation / docs /SRT /ToVideo.md
Lenylvt's picture
Rename docs/SRT to Video/API.md to docs/SRT/ToVideo.md
31c9688 verified
|
raw
history blame
No virus
3 kB

API Documentation for Lenylvt/SRT_to_Video-API

This documentation covers how to interact with the SRT_to_Video API using both Python and JavaScript.

API Endpoint

To use this API, you can choose between the gradio_client Python library docs or the @gradio/client JavaScript package doc.

Python Usage

Step 1: Installation

First, install the gradio_client if it's not already installed.

pip install gradio_client

Step 2: Making a Request

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.

API Name: /predict

from gradio_client import Client

client = Client("Lenylvt/SRT_to_Video-API")
result = client.predict(
    {
        "video": "https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4",
        "subtitles": None
    },  # Dict(video: filepath, subtitles: filepath | None) in 'Video' Video component
    "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf",  # filepath in 'Subtitle' File component
    "Hard",  # Literal['Hard', 'Soft'] in 'Subtitle Type' Radio component
    "en",  # str in 'Subtitle Language (ISO 639-1 code, e.g., 'en' for English)' Textbox component
    api_name="/predict"
)
print(result)

Return Type(s):

  • A Dict(video: filepath, subtitles: filepath | None) representing the output in the 'Processed Video' Video component.

JavaScript Usage

Step 1: Installation

For JavaScript, install the @gradio/client package if it's not already present in your project.

npm i -D @gradio/client

Step 2: Making a Request

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.

API Name: /predict

import { client } from "@gradio/client";

const response_0 = await fetch("[object Object]");
const exampleVideo = await response_0.blob();
                        
const response_1 = await fetch("https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf");
const exampleFile = await response_1.blob();
                        
const app = await client("Lenylvt/SRT_to_Video-API");
const result = await app.predict("/predict", [
    exampleVideo,  // blob in 'Video' Video component
    exampleFile,   // blob in 'Subtitle' File component        
    "Hard",        // string in 'Subtitle Type' Radio component        
    "en",          // string in 'Subtitle Language (ISO 639-1 code, e.g., 'en' for English)' Textbox component
]);

console.log(result.data);

Return Type(s):

  • undefined representing the output in the 'Processed Video' Video component.