Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,58 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import asyncio
|
| 3 |
-
import os
|
| 4 |
-
from
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
st.
|
| 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 |
st.write("You'll be able to speak your question directly to Ajoy.")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import asyncio
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime # For unique filenames
|
| 5 |
+
from llm_response import get_response
|
| 6 |
+
from male_voice import text_to_speech
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="Ajoy Prasad Bot", layout="centered")
|
| 9 |
+
st.title("Bot on behalf of Ajoy Prasad")
|
| 10 |
+
|
| 11 |
+
# Persistent directory
|
| 12 |
+
PERSISTENT_DIR = "/data/audio_responses"
|
| 13 |
+
os.makedirs(PERSISTENT_DIR, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
tab_text, tab_voice = st.tabs(["Type Your Question", "Voice Input (Coming Soon)"])
|
| 16 |
+
|
| 17 |
+
with tab_text:
|
| 18 |
+
user_input = st.text_input(
|
| 19 |
+
"Type your question and press Enter:",
|
| 20 |
+
placeholder="Ask Ajoy anything...",
|
| 21 |
+
key="text_input",
|
| 22 |
+
label_visibility="collapsed"
|
| 23 |
+
)
|
| 24 |
+
if user_input:
|
| 25 |
+
with st.spinner("Ajoy is thinking..."):
|
| 26 |
+
try:
|
| 27 |
+
response = asyncio.run(get_response(user_input))
|
| 28 |
+
|
| 29 |
+
# Generate unique filename
|
| 30 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 31 |
+
audio_file = os.path.join(PERSISTENT_DIR, f"response_{timestamp}.wav")
|
| 32 |
+
|
| 33 |
+
asyncio.run(text_to_speech(response, audio_file))
|
| 34 |
+
|
| 35 |
+
if os.path.exists(audio_file):
|
| 36 |
+
# Serve from persistent path
|
| 37 |
+
st.audio(audio_file, format="audio/wav", autoplay=True)
|
| 38 |
+
|
| 39 |
+
# Optional: Provide download link for "use anywhere"
|
| 40 |
+
with open(audio_file, "rb") as f:
|
| 41 |
+
st.download_button(
|
| 42 |
+
label="Download Audio",
|
| 43 |
+
data=f.read(),
|
| 44 |
+
file_name=os.path.basename(audio_file),
|
| 45 |
+
mime="audio/wav"
|
| 46 |
+
)
|
| 47 |
+
else:
|
| 48 |
+
st.warning("Audio file not generated.")
|
| 49 |
+
|
| 50 |
+
st.markdown("### **Ajoy's Answer:**")
|
| 51 |
+
st.write(response)
|
| 52 |
+
except Exception as e:
|
| 53 |
+
st.error(f"An error occurred: {str(e)}")
|
| 54 |
+
st.info("Please try again with a different question.")
|
| 55 |
+
|
| 56 |
+
with tab_voice:
|
| 57 |
+
st.info("Voice input feature coming soon!")
|
| 58 |
st.write("You'll be able to speak your question directly to Ajoy.")
|