shuka_demo / app.py
archit11's picture
Update app.py
2ba8923 verified
raw
history blame
1.13 kB
import transformers
import gradio as gr
import librosa
import torch
import spaces
@spaces.GPU(duration=120)
def transcribe_and_respond(audio_file):
try:
pipe = transformers.pipeline(
model='sarvamai/shuka_v1',
trust_remote_code=True,
device=0,
torch_dtype=torch.bfloat16
)
audio, sr = librosa.load(audio_file, sr=16000)
turns = [
{'role': 'system', 'content': 'Respond naturally and informatively.'},
{'role': 'user', 'content': ''}
]
output = pipe({'audio': audio, 'turns': turns, 'sampling_rate': sr}, max_new_tokens=512)
return output
except Exception as e:
return f"Error: {str(e)}"
iface = gr.Interface(
fn=transcribe_and_respond,
inputs=gr.Audio(sources="microphone", type="filepath"), # Accept audio input from microphone
outputs="text", # Output as text
title="Live Transcription and Response",
description="Speak into your microphone, and the model will respond naturally and informatively.",
live=True # Enable live processing
)
if __name__ == "__main__":
iface.launch()