# Import required modules import whisper import os from groq import Groq from gtts import gTTS import gradio as gr # Load Whisper model for transcription model = whisper.load_model("base") # Initialize Groq API client (replace with your actual API key) GROQ_API_KEY = "your_groq_api_key_here" client = Groq(api_key=GROQ_API_KEY) # Function to transcribe audio using Whisper def transcribe_audio(audio): # Transcribe the input audio file result = model.transcribe(audio) return result['text'] # Function to send the transcription to Groq API for UK Healthcare model response def query_llm(text): # Adding a healthcare context to the prompt prompt = f"The user is asking about UK healthcare services. Answer accurately and provide information relevant to the UK's healthcare system, including NHS services. The question is: {text}" chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": prompt, } ], model="llama3-8b-8192", # Specify the model here ) return chat_completion.choices[0].message.content # Function to convert text to speech using gTTS def text_to_speech(text): tts = gTTS(text) output_file = "response.mp3" tts.save(output_file) return output_file # Gradio function that ties everything together for UK healthcare chatbot def healthcare_voice_to_voice(audio): # Step 1: Transcribe the voice input transcription = transcribe_audio(audio) # Step 2: Send transcription to Groq API with UK healthcare context llm_response = query_llm(transcription) # Step 3: Convert LLM response to speech response_audio = text_to_speech(llm_response) return response_audio # Define custom CSS for the background color and heading custom_css = """ body { background-color: grey; } h1 { text-align: center; color: white; font-size: 30px; } """ # Gradio interface for UK healthcare chatbot with a custom title and theme gr.Interface( fn=healthcare_voice_to_voice, inputs=gr.Audio(type="filepath"), # For audio input from file or microphone outputs=gr.Audio(type="filepath"), # For audio output as a file title="UK Healthcare ChatBot", # Add a title for the chatbot css=custom_css # Apply the custom CSS for styling ).launch()