Qudrat0708 commited on
Commit
dfee265
·
verified ·
1 Parent(s): df9e5cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -3,7 +3,7 @@ import whisper
3
  from gtts import gTTS
4
  import gradio as gr
5
  from groq import Groq
6
- from transformers import pipeline
7
 
8
  GROQ_API_KEY = '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'
9
 
@@ -13,8 +13,8 @@ model = whisper.load_model("large") # Use "large" or "multilingual" for better
13
  # Set up Groq API client
14
  client = Groq(api_key=GROQ_API_KEY)
15
 
16
- # Load the translation model
17
- translator = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
18
 
19
  # Function to get the LLM response from Groq
20
  def get_llm_response(user_input):
@@ -39,8 +39,8 @@ def chatbot(audio):
39
  # Step 2: Get LLM response from Groq (in English)
40
  response_text = get_llm_response(user_text)
41
 
42
- # Step 3: Translate the response from English to Urdu
43
- translated_response = translator(response_text)[0]['translation_text']
44
 
45
  # Step 4: Convert the translated response text to Urdu speech
46
  output_audio = text_to_speech(translated_response)
@@ -50,7 +50,7 @@ def chatbot(audio):
50
  # Gradio interface for real-time interaction with live microphone input
51
  iface = gr.Interface(
52
  fn=chatbot,
53
- inputs=gr.Audio(type="filepath"),
54
  outputs=[gr.Textbox(), gr.Audio(type="filepath")], # Output: Urdu text and audio
55
  live=True
56
  )
 
3
  from gtts import gTTS
4
  import gradio as gr
5
  from groq import Groq
6
+ from googletrans import Translator # Translator for language conversion
7
 
8
  GROQ_API_KEY = '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'
9
 
 
13
  # Set up Groq API client
14
  client = Groq(api_key=GROQ_API_KEY)
15
 
16
+ # Set up Translator
17
+ translator = Translator()
18
 
19
  # Function to get the LLM response from Groq
20
  def get_llm_response(user_input):
 
39
  # Step 2: Get LLM response from Groq (in English)
40
  response_text = get_llm_response(user_text)
41
 
42
+ # Step 3: Translate the English response to Urdu
43
+ translated_response = translator.translate(response_text, src='en', dest='ur').text
44
 
45
  # Step 4: Convert the translated response text to Urdu speech
46
  output_audio = text_to_speech(translated_response)
 
50
  # Gradio interface for real-time interaction with live microphone input
51
  iface = gr.Interface(
52
  fn=chatbot,
53
+ inputs=gr.Audio(source="microphone", type="filepath"), # Real-time input from mic
54
  outputs=[gr.Textbox(), gr.Audio(type="filepath")], # Output: Urdu text and audio
55
  live=True
56
  )