Spaces:
Sleeping
Sleeping
datascientist22
commited on
Commit
•
2368c75
1
Parent(s):
b3a7680
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
14 |
+
st.info("Listening...")
|
15 |
+
audio = recognizer.listen(source)
|
16 |
+
try:
|
17 |
+
text = recognizer.recognize_google(audio)
|
18 |
+
return text
|
19 |
+
except sr.UnknownValueError:
|
20 |
+
return "Sorry, I could not understand the audio."
|
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 |
+
# Call the API of an avatar service (e.g., D-ID, Synthesia)
|
27 |
+
api_url = "https://api.example.com/generate-avatar"
|
28 |
+
payload = {"text": text_response}
|
29 |
+
response = requests.post(api_url, json=payload)
|
30 |
+
video_url = response.json().get("video_url")
|
31 |
+
return video_url
|
32 |
+
|
33 |
+
st.title("🗣️ Live Video Chatbot")
|
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 |
+
# Generate chatbot response
|
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
|
49 |
+
st.video(video_url)
|