Spaces:
Runtime error
Runtime error
import spaces | |
import gradio as gr | |
from transformers import pipeline | |
# Initialize model and move to GPU | |
model = pipeline( | |
"automatic-speech-recognition", | |
model="Aekanun/whisper-small-hi", | |
device="cuda" # เปลี่ยนเป็น cuda เลย | |
) | |
# GPU function with default 60s duration | |
def transcribe_speech(audio): | |
"""Speech transcription function""" | |
try: | |
if audio is None: | |
return "กรุณาบันทึกเสียงก่อน" | |
# Process audio (model is already on GPU) | |
result = model(audio, batch_size=1) | |
# Get text result | |
text = result["text"] if isinstance(result, dict) else result | |
return text | |
except Exception as e: | |
return f"เกิดข้อผิดพลาด: {str(e)}" | |
# Create Gradio interface | |
demo = gr.Interface( | |
fn=transcribe_speech, | |
inputs=gr.Audio(type="filepath"), | |
outputs=gr.Textbox(label="ข้อความ"), | |
title="Thai Speech Transcription", | |
description="บันทึกเสียงเพื่อแปลงเป็นข้อความภาษาไทย", | |
) | |
if __name__ == "__main__": | |
demo.queue().launch(server_name="0.0.0.0") |