Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,9 @@ def get_llm_response(prompt):
|
|
| 21 |
return response.choices[0].message.content.strip()
|
| 22 |
|
| 23 |
def process_voice_or_text(input_audio, input_text, output_lang):
|
|
|
|
|
|
|
|
|
|
| 24 |
if input_audio is not None:
|
| 25 |
# Process audio input
|
| 26 |
recognizer = sr.Recognizer()
|
|
@@ -47,6 +50,18 @@ def process_voice_or_text(input_audio, input_text, output_lang):
|
|
| 47 |
|
| 48 |
return input_text, english_query, llm_response, final_response
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def text_to_speech(response, lang):
|
| 51 |
tts = gTTS(text=response, lang=lang)
|
| 52 |
tts.save("response.mp3")
|
|
|
|
| 21 |
return response.choices[0].message.content.strip()
|
| 22 |
|
| 23 |
def process_voice_or_text(input_audio, input_text, output_lang):
|
| 24 |
+
if output_lang not in ["ta", "en"]:
|
| 25 |
+
return "Invalid output language selected. Please choose either Tamil ('ta') or English ('en').", "", "", ""
|
| 26 |
+
|
| 27 |
if input_audio is not None:
|
| 28 |
# Process audio input
|
| 29 |
recognizer = sr.Recognizer()
|
|
|
|
| 50 |
|
| 51 |
return input_text, english_query, llm_response, final_response
|
| 52 |
|
| 53 |
+
|
| 54 |
+
# Translate input to English
|
| 55 |
+
english_query = translate_text(input_text, "en")
|
| 56 |
+
|
| 57 |
+
# Get response from LLM
|
| 58 |
+
llm_response = get_llm_response(english_query)
|
| 59 |
+
|
| 60 |
+
# Translate LLM response to desired output language
|
| 61 |
+
final_response = translate_text(llm_response, output_lang)
|
| 62 |
+
|
| 63 |
+
return input_text, english_query, llm_response, final_response
|
| 64 |
+
|
| 65 |
def text_to_speech(response, lang):
|
| 66 |
tts = gTTS(text=response, lang=lang)
|
| 67 |
tts.save("response.mp3")
|