File size: 4,953 Bytes
d0fcdcf
adcbc15
 
 
 
d0fcdcf
 
 
 
 
 
 
 
dadcb61
 
 
 
 
03ba989
 
 
 
 
 
 
 
 
 
 
dadcb61
 
 
03ba989
dadcb61
 
 
 
 
03ba989
dadcb61
 
 
 
 
03ba989
dadcb61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03ba989
dadcb61
 
 
 
 
 
03ba989
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dadcb61
 
 
 
03ba989
 
dadcb61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03ba989
 
 
 
 
 
 
 
 
 
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
---
title: AI-powered ASL text-to-video Generator
emoji: 🐻
colorFrom: blue
colorTo: yellow
sdk: gradio
sdk_version: 5.34.2
app_file: app.py
pinned: false
license: apache-2.0
---

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

# AI-SL API

Convert text documents to American Sign Language (ASL) videos using AI.

## Features

### Dual Input Support with Optional File Upload
The app accepts both text input and file uploads with flexible options:

- **Text Input**: Type or paste text directly into the interface (always available)
- **File Upload**: Upload documents (PDF, TXT, DOCX, EPUB) - **optional, can be enabled/disabled**
- **Smart Priority**: Text input takes priority if both are provided
- **Toggle Control**: Checkbox to enable/disable file upload functionality

### Video Output Options

The Gradio interface provides multiple ways for users to receive and download the generated ASL videos:

#### 1. R2 Cloud Storage (Recommended)
- Videos are automatically uploaded to Cloudflare R2 storage
- Returns a public URL that users can download directly
- Videos persist and can be shared via URL
- Includes a styled download button in the interface

#### 2. Base64 Encoding (Alternative)
- Videos are embedded as base64 data directly in the response
- No external storage required
- Good for smaller videos or when you want to avoid cloud storage
- Can be downloaded directly from the interface

#### 3. Programmatic Access
Users can access the video output programmatically using:

```python
from gradio_client import Client

# Connect to the running interface
client = Client("http://localhost:7860")

# Upload a document and get results
result = client.predict(
    "path/to/document.pdf",
    api_name="/predict"
)

# The result contains: (json_data, video_output, download_html)
json_data, video_url, download_html = result

# Download the video
import requests
response = requests.get(video_url)
with open("asl_video.mp4", "wb") as f:
    f.write(response.content)
```

#### 4. Direct Download from Interface
- The interface includes a styled download button
- Users can right-click and "Save As" if automatic download doesn't work
- Video files are named `asl_video.mp4` by default

## Example Usage

### Web Interface
1. Visit your Space URL
2. Choose input method:
   - **Text**: Type or paste text in the text box (always available)
   - **File**: Check "Enable file upload" and upload a document (optional)
3. Click "Generate ASL Video"
4. Download the resulting video

### Programmatic Access with Optional File Upload

```python
from gradio_client import Client

# Connect to your hosted app
client = Client("https://huggingface.co/spaces/your-username/your-space")

# Text input only (file upload disabled)
result = client.predict(
    "Hello world! This is a test.",  # Text input
    False,                           # Enable file upload (False = disabled)
    None,                            # File input (None since disabled)
    True,                            # Use R2 storage
    api_name="/predict"
)

# File input only (file upload enabled)
result = client.predict(
    "",                              # Text input (empty)
    True,                            # Enable file upload (True = enabled)
    "document.pdf",                  # File input
    True,                            # Use R2 storage
    api_name="/predict"
)

# Both inputs (text takes priority)
result = client.predict(
    "Quick text",                    # Text input
    True,                            # Enable file upload (True = enabled)
    "document.pdf",                  # File input
    True,                            # Use R2 storage
    api_name="/predict"
)
```

See `example_usage.py`, `example_usage_dual_input.py`, and `example_optional_file_upload.py` for complete examples of how to:
- Download videos from URLs
- Process base64 video data
- Use the interface programmatically
- Perform further video processing
- Handle both text and file inputs
- Use optional file upload functionality

## Requirements

- Python 3.7+
- Required packages listed in `requirements.txt`
- Cloudflare R2 credentials (for cloud storage option)
- Supabase credentials for video database

## Setup

1. Install dependencies: `pip install -r requirements.txt`
2. Set up environment variables in `.env` file
3. Run the interface: `python app.py`

## Video Processing

Once you have the video file, you can:
- Upload to YouTube, Google Drive, or other services
- Analyze with OpenCV for computer vision tasks
- Convert to different formats
- Extract frames for further processing
- Add subtitles or overlays

## Deployment to Hugging Face Spaces

1. Create a new Space on Hugging Face
2. Choose Gradio as the SDK
3. Upload your code files
4. Set environment variables in Space settings
5. Deploy and share your Space URL

Your app will be accessible to users worldwide with flexible input options!