import streamlit as st import openai import whisper import threading import time from gtts import gTTS from IPython.display import Audio # Streamlit UI setup st.title("Real-Time Video-Calling AI Avatar Chatbot") # Load Whisper model for speech-to-text whisper_model = whisper.load_model("base") # OpenAI API setup openai.api_key = 'YOUR_OPENAI_API_KEY' # Text-to-Speech function using gTTS def text_to_speech(text): tts = gTTS(text=text, lang='en') audio_fp = '/tmp/response.mp3' tts.save(audio_fp) return audio_fp # Play the audio in Colab def play_audio(audio_fp): return Audio(audio_fp) # Get AI response using OpenAI API def get_ai_response(text): prompt = f'User: {text}\nAI:' response = openai.Completion.create( engine='text-davinci-003', prompt=prompt, max_tokens=150 ) return response.choices[0].text.strip() # Function to handle video call def video_call(): # Placeholder for webcam capture # For demonstration, we use text as input (you can integrate actual webcam input) user_input = "Hello AI, how are you?" # Get response from AI ai_response = get_ai_response(user_input) # Convert the response to speech audio_fp = text_to_speech(ai_response) # Play the response play_audio(audio_fp) # Start video call in Streamlit if st.button("Start Video Call"): video_call()