dindizz's picture
Update app.py
f106e32 verified
import openai
import gradio as gr
from dotenv import load_dotenv
import os
# Load environment variables from .env file
load_dotenv()
# Set up OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
def speech_to_text(audio):
# Check if the audio input is received correctly
if audio is None:
return "No audio file uploaded."
try:
# Transcribe the audio to text using OpenAI's Whisper API via the new method
with open(audio, "rb") as audio_file:
response = openai.Audio.transcribe(
model="whisper-1", # Use the appropriate model for transcription
file=audio_file,
language="ta" # Specify the language as Tamil
)
text = response['text']
return text
except Exception as e:
return f"Error during transcription: {str(e)}"
# Set up the Gradio interface
interface = gr.Interface(
fn=speech_to_text,
inputs=gr.Audio(type="filepath"),
outputs="text",
title="Speech to Text Transcription",
description="Transcribe speech to Tamil text using."
)
# Launch the interface
if __name__ == "__main__":
interface.launch()