datascientist22
commited on
Commit
•
1b365e4
1
Parent(s):
2368c75
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
import streamlit as st
|
2 |
import speech_recognition as sr
|
3 |
from transformers import pipeline
|
4 |
-
from tts import TTS # Hugging Face TTS model
|
5 |
import requests
|
6 |
|
7 |
-
# Load the chatbot model
|
8 |
chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
9 |
|
10 |
-
# Function to convert speech to text
|
11 |
def speech_to_text():
|
12 |
recognizer = sr.Recognizer()
|
13 |
with sr.Microphone() as source:
|
@@ -21,28 +20,41 @@ def speech_to_text():
|
|
21 |
except sr.RequestError:
|
22 |
return "Speech recognition service is not available."
|
23 |
|
24 |
-
# Function to generate avatar video
|
25 |
def generate_avatar_video(text_response):
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
return video_url
|
32 |
|
33 |
-
|
|
|
34 |
|
35 |
# Button to start recording
|
36 |
if st.button("Speak"):
|
37 |
user_input = speech_to_text()
|
38 |
if user_input:
|
39 |
st.write(f"**You:** {user_input}")
|
40 |
-
|
|
|
41 |
bot_response = chatbot(user_input)
|
42 |
response_text = bot_response[0]["generated_text"]
|
43 |
st.write(f"**Bot:** {response_text}")
|
44 |
|
45 |
-
# Generate avatar video
|
46 |
video_url = generate_avatar_video(response_text)
|
47 |
|
48 |
# Display the video response
|
|
|
1 |
import streamlit as st
|
2 |
import speech_recognition as sr
|
3 |
from transformers import pipeline
|
|
|
4 |
import requests
|
5 |
|
6 |
+
# Load the chatbot model from Hugging Face
|
7 |
chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
8 |
|
9 |
+
# Function to convert speech to text using SpeechRecognition
|
10 |
def speech_to_text():
|
11 |
recognizer = sr.Recognizer()
|
12 |
with sr.Microphone() as source:
|
|
|
20 |
except sr.RequestError:
|
21 |
return "Speech recognition service is not available."
|
22 |
|
23 |
+
# Function to generate avatar video using D-ID API
|
24 |
def generate_avatar_video(text_response):
|
25 |
+
api_url = "https://api.d-id.com/talk"
|
26 |
+
headers = {
|
27 |
+
"Authorization": "Bearer YOUR_API_KEY", # Replace with your D-ID API Key
|
28 |
+
"Content-Type": "application/json"
|
29 |
+
}
|
30 |
+
payload = {
|
31 |
+
"script": {
|
32 |
+
"type": "text",
|
33 |
+
"input": text_response
|
34 |
+
},
|
35 |
+
"source": {
|
36 |
+
"avatar_id": "your_avatar_id" # Replace with the desired avatar ID
|
37 |
+
}
|
38 |
+
}
|
39 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
40 |
+
video_url = response.json().get("result_url")
|
41 |
return video_url
|
42 |
|
43 |
+
# Streamlit app interface
|
44 |
+
st.title("🗣️ Voice-Enabled Live Video Chatbot")
|
45 |
|
46 |
# Button to start recording
|
47 |
if st.button("Speak"):
|
48 |
user_input = speech_to_text()
|
49 |
if user_input:
|
50 |
st.write(f"**You:** {user_input}")
|
51 |
+
|
52 |
+
# Generate chatbot response using NLP model
|
53 |
bot_response = chatbot(user_input)
|
54 |
response_text = bot_response[0]["generated_text"]
|
55 |
st.write(f"**Bot:** {response_text}")
|
56 |
|
57 |
+
# Generate avatar video with the bot's response
|
58 |
video_url = generate_avatar_video(response_text)
|
59 |
|
60 |
# Display the video response
|