File size: 1,373 Bytes
b436fe9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()