Spaces:
Sleeping
Sleeping
File size: 1,838 Bytes
0552130 |
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 |
# app.py
import streamlit as st
import asyncio
import os
from pathlib import Path
from llm_response import get_response
from male_voice import text_to_speech_async
# Page config
st.set_page_config(page_title="Ajoy Prasad Bot", layout="centered")
st.title("Ajoy Prasad Bot")
st.caption("Ask me anything — I’ll answer in text and voice!")
# Tabs
tab_text, tab_voice = st.tabs(["Type Your Question", "Voice Input (Coming Soon)"])
with tab_text:
user_input = st.text_input(
"Type your question and press Enter:",
placeholder="Ask Ajoy anything...",
key="text_input",
label_visibility="collapsed"
)
if user_input:
with st.spinner("Ajoy is thinking..."):
try:
# Get LLM response
response = asyncio.run(get_response(user_input))
# Generate unique audio file
audio_file = Path("response.wav")
# Generate speech (async, non-blocking)
success = asyncio.run(text_to_speech_async(response, audio_file))
# Show response
st.markdown("### **Ajoy's Answer:**")
st.write(response)
# Play audio
if success and audio_file.exists():
st.audio(str(audio_file), format="audio/wav", autoplay=True)
else:
st.warning("Audio could not be generated.")
except Exception as e:
st.error(f"An error occurred: {str(e)}")
st.info("Please try again with a different question.")
with tab_voice:
st.info("Voice input feature coming soon!")
st.write("You'll be able to speak your question directly to Ajoy.")
st.caption("Stay tuned for microphone support!") |