import os import gradio as gr from gtts import gTTS import whisper from groq import Groq import numpy as np import librosa from nltk.corpus import wordnet from deep_translator import GoogleTranslator # Set up Groq API client api_key = os.getenv("GROQ_API_KEY") client = Groq(api_key=api_key) # Load Whisper model model = whisper.load_model("base") def text_to_speech(text): tts = gTTS(text=text, lang='en') audio_file_path = "output.mp3" tts.save(audio_file_path) return audio_file_path def chatbot(audio): try: if audio is None: return "Error: No audio input provided." audio_data, sample_rate = librosa.load(audio, sr=16000) if not np.issubdtype(audio_data.dtype, np.floating): audio_data = audio_data.astype(np.float32) transcription = model.transcribe(audio_data) user_input = transcription["text"] messages = [ {"role": "system", "content": "You are an English tutor. Your job is to provide detailed feedback on grammar and vocabulary."}, {"role": "user", "content": f"Please review the following text and provide feedback on grammar and vocabulary: {user_input}"} ] chat_completion = client.chat.completions.create( messages=messages, model="llama3-groq-70b-8192-tool-use-preview", ) response_text = chat_completion.choices[0].message.content return response_text except Exception as e: return f"Error: {str(e)}" def get_synonyms(word): try: synonyms = wordnet.synsets(word) english_synonyms = set() translator = GoogleTranslator(source='en', target='ur') for syn in synonyms: for lemma in syn.lemmas(): english_synonyms.add(lemma.name()) urdu_synonyms = [translator.translate(word) for word in english_synonyms] return f"English Synonyms: {', '.join(english_synonyms)}", f"Urdu Synonyms: {', '.join(urdu_synonyms)}" except Exception as e: return f"An error occurred: {e}", "" def build_interface(): with gr.Blocks() as demo: gr.Markdown( """