Views
No views yet
hf-ibm-granite-speech/
├── handler.py # Custom handler implementation
├── requirements.txt # Python dependencies
├── README.md # This file
└── CLAUDE.md # AI documentationhandler.py and requirements.txt to the repohandler.py and requirements.txt in the repo root1# Encode audio file to base64
2AUDIO_BASE64=$(base64 -w 0 audio.wav)
3
4curl -X POST https://your-endpoint.endpoints.huggingface.cloud \
5 -H "Authorization: Bearer $HF_TOKEN" \
6 -H "Content-Type: application/json" \
7 -d "{
8 \"inputs\": \"$AUDIO_BASE64\",
9 \"parameters\": {
10 \"prompt\": \"can you transcribe the speech into a written format?\",
11 \"max_new_tokens\": 200,
12 \"num_beams\": 4
13 }
14 }"1import base64
2import requests
3
4# Load and encode audio
5with open("audio.wav", "rb") as f:
6 audio_base64 = base64.b64encode(f.read()).decode("utf-8")
7
8# Make request
9response = requests.post(
10 "https://your-endpoint.endpoints.huggingface.cloud",
11 headers={"Authorization": f"Bearer {HF_TOKEN}"},
12 json={
13 "inputs": audio_base64,
14 "parameters": {
15 "prompt": "can you transcribe the speech into a written format?",
16 "max_new_tokens": 200
17 }
18 }
19)
20
21result = response.json()
22if "text" in result:
23 print(f"Transcription: {result['text']}")
24else:
25 print(f"Error: {result['error']}")1{
2 "text": "THIS IS THE TRANSCRIBED TEXT FROM THE AUDIO."
3}1{
2 "error": "ErrorType: Error message\nFull stack trace..."
3}| Parameter | Type | Default | Description |
|---|---|---|---|
inputs | string | required | Base64-encoded audio data |
prompt | string | "can you transcribe..." | Instruction prompt for the model |
system_prompt | string | (default IBM prompt) | System prompt for the model |
max_new_tokens | int | 200 | Maximum tokens to generate |
num_beams | int | 4 | Number of beams for beam search |
do_sample | bool | false | Whether to use sampling |
temperature | float | 1.0 | Sampling temperature |
top_p | float | 1.0 | Nucleus sampling parameter |
repetition_penalty | float | 3.0 | Penalty for repeated tokens |
length_penalty | float | 1.0 | Length penalty for beam search |
1{
2 "inputs": "<base64-audio>",
3 "parameters": {
4 "prompt": "Please provide a detailed transcription with punctuation."
5 }
6}MODEL_ID environment variable in your endpoint configuration:MODEL_ID=your-org/your-fine-tuned-granite-speechmax_new_tokensnum_beams to 2