-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
148 lines (123 loc) · 5.26 KB
/
app.py
File metadata and controls
148 lines (123 loc) · 5.26 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import streamlit as st
import time
from Deep_Assistant import VoiceAssistant
import streamlit.components.v1 as components
st.set_page_config(page_title="Magical Voice Assistant", layout="wide")
# Custom CSS for black-hole magical animations
def load_css():
st.markdown("""
<style>
body {
margin: 0;
padding: 0;
background: radial-gradient(circle, #000000, #1a1a1a, #000000, #ffd700);
height: 100vh;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
.black-hole {
position: absolute;
top: 50%;
left: 50%;
width: 300px;
height: 300px;
background: radial-gradient(circle, #000000, #1a1a1a, #000000);
border-radius: 50%;
box-shadow: 0 0 50px #ffd700, inset 0 0 50px #ffffff;
transform: translate(-50%, -50%);
}
.black-hole::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 500px;
height: 500px;
border-radius: 50%;
background: radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0));
box-shadow: 0 0 60px 30px rgba(255, 255, 255, 0.3);
transform: translate(-50%, -50%);
z-index: -1;
}
@keyframes circular-motion {
0% { transform: translate(-50%, -50%) rotate(0deg) translateX(200px) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg) translateX(200px) rotate(-360deg); }
}
.magical-ball {
width: 50px;
height: 50px;
border-radius: 50%;
background: radial-gradient(circle at 30% 30%, #ffd700, #ffffff);
box-shadow: 0 0 20px #ffd700, inset 0 0 20px #ffffff;
position: absolute;
top: 50%;
left: 50%;
animation: circular-motion 5s linear infinite;
}
.container {
position: relative;
z-index: 10;
text-align: center;
color: #ffffff;
padding: 2rem;
}
.status-text {
color: #ffd700;
text-align: center;
font-size: 1.5rem;
margin-top: 2rem;
text-shadow: 0 0 10px #ffffff;
}
</style>
""", unsafe_allow_html=True)
def main():
load_css()
# Add the black hole and magical ball
st.markdown('<div class="black-hole"></div>', unsafe_allow_html=True)
st.markdown('<div class="magical-ball"></div>', unsafe_allow_html=True)
# Main container
with st.container():
st.markdown('<div class="container">', unsafe_allow_html=True)
st.title("✨ Magical Black-Hole Voice Assistant ✨")
# Initialize voice assistant
if 'assistant' not in st.session_state:
st.session_state.assistant = VoiceAssistant()
st.session_state.status = "Waiting..."
st.session_state.conversation = []
# Status display
status_placeholder = st.empty()
conversation_placeholder = st.empty()
# Start/Stop button
if st.button("🎙️ Start Listening", key="start_button"):
try:
status_placeholder.markdown('<p class="status-text">Listening...</p>', unsafe_allow_html=True)
# Get audio input
audio_bytes = st.session_state.assistant.listen_for_speech()
status_placeholder.markdown('<p class="status-text">Processing speech...</p>', unsafe_allow_html=True)
# Convert speech to text
text = st.session_state.assistant.speech_to_text(audio_bytes)
if text:
# Get AI response
status_placeholder.markdown('<p class="status-text">Getting response...</p>', unsafe_allow_html=True)
response_text = st.session_state.assistant.chat(text)
# Add to conversation history
st.session_state.conversation.append({"user": text, "assistant": response_text})
# Convert response to speech
status_placeholder.markdown('<p class="status-text">Speaking...</p>', unsafe_allow_html=True)
audio_stream = st.session_state.assistant.text_to_speech(response_text)
st.session_state.assistant.stream_audio(audio_stream)
# Display conversation
with conversation_placeholder.container():
for conv in st.session_state.conversation:
st.markdown(f"**You:** {conv['user']}")
st.markdown(f"**Assistant:** {conv['assistant']}")
st.markdown("---")
status_placeholder.markdown('<p class="status-text">Ready for next input!</p>', unsafe_allow_html=True)
except Exception as e:
st.error(f"An error occurred: {str(e)}")
status_placeholder.markdown('<p class="status-text">Error occurred!</p>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)
if __name__ == "__main__":
main()