Spaces:
Runtime error
Runtime error
| #uvicorn app:app --host 0.0.0.0 --port 8000 --reload | |
| # from fastapi import FastAPI | |
| # from transformers import pipeline | |
| # pipe = pipeline("automatic-speech-recognition", model="Pranjal12345/whisper-small-ne-pranjal") | |
| # audio_path = "/home/pranjal/Downloads/chinese_audio.mp3" | |
| # with open("/home/pranjal/Downloads/chinese_audio.mp3", "rb") as audio_file: | |
| # audio_data = audio_file.read() | |
| # app = FastAPI() | |
| # @app.get("/") | |
| # def hello(): | |
| # output = pipe(input) | |
| # return {"Output": output} | |
| from fastapi import FastAPI | |
| from transformers import WhisperProcessor, WhisperForConditionalGeneration | |
| import librosa | |
| app = FastAPI() | |
| # Load model and processor | |
| processor = WhisperProcessor.from_pretrained("openai/whisper-small") | |
| model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small") | |
| model.config.forced_decoder_ids = None | |
| # Path to your audio file | |
| audio_file_path = "output.mp3" | |
| # Read the audio file | |
| audio_data, _ = librosa.load(audio_file_path, sr=16000) | |
| def transcribe_audio(): | |
| # Process the audio data using the Whisper processor | |
| input_features = processor(audio_data.tolist(), return_tensors="pt").input_features | |
| # Generate transcription | |
| predicted_ids = model.generate(input_features) | |
| transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True) | |
| return {"transcription": transcription[0]} | |