Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import torch
|
|
| 3 |
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
| 4 |
import soundfile as sf
|
| 5 |
import openai
|
| 6 |
-
from
|
| 7 |
import os
|
| 8 |
|
| 9 |
# Load the Wav2Vec2 model and processor for Tamil
|
|
@@ -13,9 +13,6 @@ processor = Wav2Vec2Processor.from_pretrained("Harveenchadha/wav2vec2-large-xlsr
|
|
| 13 |
# Initialize OpenAI API
|
| 14 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 15 |
|
| 16 |
-
# Initialize Google Translator
|
| 17 |
-
translator = Translator()
|
| 18 |
-
|
| 19 |
def transcribe_audio(audio_path):
|
| 20 |
# Load audio file
|
| 21 |
audio_input, _ = sf.read(audio_path)
|
|
@@ -42,8 +39,8 @@ def get_llm_response(prompt):
|
|
| 42 |
return response.choices[0].text.strip()
|
| 43 |
|
| 44 |
def translate_text(text, target_lang):
|
| 45 |
-
|
| 46 |
-
return
|
| 47 |
|
| 48 |
def process_voice_input(audio_path, output_lang):
|
| 49 |
# Transcribe audio
|
|
@@ -77,4 +74,5 @@ iface = gr.Interface(
|
|
| 77 |
description="Speak in Tamil, get responses in Tamil or English!"
|
| 78 |
)
|
| 79 |
|
| 80 |
-
iface.launch()
|
|
|
|
|
|
| 3 |
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
| 4 |
import soundfile as sf
|
| 5 |
import openai
|
| 6 |
+
from deep_translator import GoogleTranslator
|
| 7 |
import os
|
| 8 |
|
| 9 |
# Load the Wav2Vec2 model and processor for Tamil
|
|
|
|
| 13 |
# Initialize OpenAI API
|
| 14 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
def transcribe_audio(audio_path):
|
| 17 |
# Load audio file
|
| 18 |
audio_input, _ = sf.read(audio_path)
|
|
|
|
| 39 |
return response.choices[0].text.strip()
|
| 40 |
|
| 41 |
def translate_text(text, target_lang):
|
| 42 |
+
translator = GoogleTranslator(source='auto', target=target_lang)
|
| 43 |
+
return translator.translate(text)
|
| 44 |
|
| 45 |
def process_voice_input(audio_path, output_lang):
|
| 46 |
# Transcribe audio
|
|
|
|
| 74 |
description="Speak in Tamil, get responses in Tamil or English!"
|
| 75 |
)
|
| 76 |
|
| 77 |
+
iface.launch()
|
| 78 |
+
|