stt-gpu-service-python-v4 / app_gradio.py
Peter Michael Gits
Fix Dockerfile directory permissions - create /app as root before switching users
26096f4
import gradio as gr
import time
import asyncio
from typing import Generator
# Global state tracking
service_info = {
"status": "running",
"model_loaded": False,
"connections": 0,
"version": "gradio-test"
}
def health_check() -> dict:
"""Health check function"""
return {
"status": "healthy",
"timestamp": time.time(),
"service": "STT GPU Service - Gradio Test",
**service_info
}
def transcribe_audio(audio_file):
"""Placeholder transcription function"""
if audio_file is None:
return "No audio file provided"
# Placeholder response
return f"Audio file received: {type(audio_file)} - Model not loaded yet (placeholder)"
def streaming_demo(audio_chunk):
"""Placeholder streaming function"""
if audio_chunk is None:
return "No audio chunk provided"
return f"Streaming chunk received - Model not loaded yet (placeholder)"
# Create Gradio interface
with gr.Blocks(title="STT GPU Service - Gradio Test") as demo:
gr.Markdown("""
# 🎙️ STT GPU Service - Gradio Test Version
This is a test deployment to verify HuggingFace Spaces functionality.
The actual STT model will be added after successful deployment.
""")
with gr.Tab("Health Check"):
health_output = gr.JSON(label="Service Status")
health_btn = gr.Button("Check Health")
health_btn.click(health_check, outputs=health_output)
with gr.Tab("File Transcription"):
gr.Markdown("Upload an audio file for transcription (placeholder)")
audio_input = gr.Audio(type="filepath", label="Upload Audio File")
transcribe_btn = gr.Button("Transcribe")
transcribe_output = gr.Textbox(label="Transcription Result")
transcribe_btn.click(transcribe_audio, inputs=audio_input, outputs=transcribe_output)
with gr.Tab("Streaming Test"):
gr.Markdown("Test streaming functionality (placeholder)")
stream_input = gr.Audio(type="numpy", label="Stream Audio")
stream_output = gr.Textbox(label="Streaming Response")
stream_input.change(streaming_demo, inputs=stream_input, outputs=stream_output)
with gr.Tab("API Info"):
gr.Markdown("""
## API Endpoints (when deployed)
- `GET /` - Service information
- `GET /health` - Health check
- `POST /transcribe` - File transcription
- `WebSocket /ws/stream` - Real-time streaming
## Technical Details
- **Model**: kyutai/stt-1b-en_fr (to be loaded)
- **Framework**: Gradio + FastAPI backend
- **GPU**: T4 Small
- **Chunk Size**: 80ms
- **Languages**: English, French
""")
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
show_api=True,
show_error=True
)