# 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!")