Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,54 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import asyncio
|
| 4 |
-
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
from llm_response import get_response
|
| 7 |
-
from male_voice import
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
st.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
"
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
response = asyncio.run(get_response(user_input))
|
| 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 |
-
st.write(response)
|
| 56 |
-
|
| 57 |
-
except Exception as e:
|
| 58 |
-
st.exception(e)
|
| 59 |
-
|
| 60 |
-
with tab_voice:
|
| 61 |
-
st.info("Voice input feature coming soon!")
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import asyncio
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from llm_response import get_response
|
| 7 |
+
from male_voice import text_to_speech_async
|
| 8 |
+
|
| 9 |
+
# Page config
|
| 10 |
+
st.set_page_config(page_title="Ajoy Prasad Bot", layout="centered")
|
| 11 |
+
st.title("Ajoy Prasad Bot")
|
| 12 |
+
st.caption("Ask me anything — I’ll answer in text and voice!")
|
| 13 |
+
|
| 14 |
+
# Tabs
|
| 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 |
+
|
| 25 |
+
if user_input:
|
| 26 |
+
with st.spinner("Ajoy is thinking..."):
|
| 27 |
+
try:
|
| 28 |
+
# Get LLM response
|
| 29 |
+
response = asyncio.run(get_response(user_input))
|
| 30 |
+
|
| 31 |
+
# Generate unique audio file
|
| 32 |
+
audio_file = Path("response.wav")
|
| 33 |
+
|
| 34 |
+
# Generate speech (async, non-blocking)
|
| 35 |
+
success = asyncio.run(text_to_speech_async(response, audio_file))
|
| 36 |
+
|
| 37 |
+
# Show response
|
| 38 |
+
st.markdown("### **Ajoy's Answer:**")
|
| 39 |
+
st.write(response)
|
| 40 |
+
|
| 41 |
+
# Play audio
|
| 42 |
+
if success and audio_file.exists():
|
| 43 |
+
st.audio(str(audio_file), format="audio/wav", autoplay=True)
|
| 44 |
+
else:
|
| 45 |
+
st.warning("Audio could not be generated.")
|
| 46 |
+
|
| 47 |
+
except Exception as e:
|
| 48 |
+
st.error(f"An error occurred: {str(e)}")
|
| 49 |
+
st.info("Please try again with a different question.")
|
| 50 |
+
|
| 51 |
+
with tab_voice:
|
| 52 |
+
st.info("Voice input feature coming soon!")
|
| 53 |
+
st.write("You'll be able to speak your question directly to Ajoy.")
|
| 54 |
+
st.caption("Stay tuned for microphone support!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|