Spaces:
Sleeping
Sleeping
File size: 4,405 Bytes
31a02eb 15f6bf4 31a02eb 15f6bf4 31a02eb 15f6bf4 31a02eb 15f6bf4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | ---
title: SRT Processing Tool
emoji: π¬
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.0.0
app_file: app.py
pinned: false
license: mit
---
# π¬ SRT Processing Tool
A production-ready web application for processing SRT subtitle files, powered by Gradio and ready for Hugging Face Spaces.
**Resegment and translate your subtitle files easily in your browser!**
## β¨ Features
- **π SRT Resegmentation**: Optimize subtitle segments by character limits, respecting punctuation boundaries
- **π SRT Translation**: Translate subtitle files using AI (OpenAI, Aliyun DashScope, or OpenRouter)
- **β‘ Automatic Resegmentation**: Translation automatically includes resegmentation for optimal chunk sizes
- **π Production Ready**: Optimized for Hugging Face Spaces deployment
## π Live Demo
**Try it live:** [https://huggingface.co/spaces/BiliSakura/SRT-Processing-Tool](https://huggingface.co/spaces/BiliSakura/SRT-Processing-Tool)
This app is deployed on Hugging Face Spaces! To deploy your own version:
1. Fork this repository
2. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
3. Create a new Space
4. Connect your GitHub repository
5. Select Gradio as the SDK
6. Set the app file to `app.py`
7. Add your API keys as secrets (see below)
8. Deploy!
## π API Keys Configuration
For translation features, add your API keys as secrets in Hugging Face Spaces:
1. Go to your Space settings
2. Navigate to "Variables and secrets"
3. Add the following secrets:
### Required Secrets (choose based on provider):
- **Aliyun DashScope**: `DASHSCOPE_API_KEY`
- **OpenAI**: `OPENAI_API_KEY`
- **OpenRouter**: `OPENROUTER_API_KEY`
### Optional Secrets (for OpenRouter attribution):
- `OPENROUTER_SITE_URL` (maps to `HTTP-Referer`)
- `OPENROUTER_APP_TITLE` (maps to `X-Title`)
## π¦ Local Installation
```bash
# Clone the repository
git clone https://huggingface.co/spaces/BiliSakura/SRT-Processing-Tool
cd SRT-Processing-Tool
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
```
## π Local Run
```bash
python app.py
```
The app will be available at `http://localhost:7860`
## π Usage
1. Open the app in your browser
2. Upload your SRT file
3. Choose operation:
- **Translate only**: Translate subtitles to target language
- **Resegment only**: Optimize subtitle segments by character limits
4. Configure settings:
- **Translation Settings**: Target language, provider, model, workers
- **Resegmentation Settings**: Maximum characters per segment
5. Click "π Process SRT File"
6. Download your processed file!
## π§ Configuration
### Default Models
- **OpenAI**: `gpt-4.1` (uses Responses API)
- **Aliyun DashScope**: `qwen-max`
- **OpenRouter**: `openai/gpt-4o`
### Environment Variables
You can also use a `.env` file for local development:
```env
# Aliyun DashScope
DASHSCOPE_API_KEY=your_key_here
# OpenAI
OPENAI_API_KEY=your_key_here
# OpenRouter
OPENROUTER_API_KEY=your_key_here
OPENROUTER_SITE_URL=https://your-site.com
OPENROUTER_APP_TITLE=Your App Title
# Optional: override model for all providers
MODEL=your_model_name
```
## π» CLI Usage
You can also use the SRT processor from the command line:
```bash
# Resegment only
python tools/srt_processor.py input.srt output.srt --operation resegment --max-chars 125
# Translate (OpenAI)
python tools/srt_processor.py input.srt output.srt --operation translate --target-lang zh --provider openai --model gpt-4.1 --workers 5
# Translate (OpenRouter)
python tools/srt_processor.py input.srt output.srt --operation translate --target-lang zh --provider openrouter --model openai/gpt-4o --workers 5
# Translate (DashScope)
python tools/srt_processor.py input.srt output.srt --operation translate --target-lang zh --provider dashscope --model qwen-max --workers 5
```
## ποΈ Project Structure
```
.
βββ app.py # Main Gradio application
βββ tools/
β βββ __init__.py
β βββ srt_processor.py # Core SRT processing logic
βββ requirements.txt # Python dependencies
βββ README.md # This file
```
## π License
MIT License
## π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
---
**Made with β€οΈ for subtitle processing**
|