import gradio as gr import os from utils import init_openai, transcribe_audio, chat_with_gpt # Load API key init_openai() # Define the system prompt for RentBot SYSTEM_PROMPT = ( "You are RentBot, a friendly virtual leasing assistant. " "You answer inquiries about rental listings, schedule showings, and provide clear instructions to potential tenants." ) def handle_interaction(audio) -> tuple[str, str]: """ Gradio handler: saves incoming audio, transcribes it, then chats with GPT. Returns the transcript and the bot response. """ # Save incoming audio to disk audio_path = "input.wav" audio.save(audio_path) # Transcribe audio -> text transcript = transcribe_audio(audio_path) # Generate bot reply reply = chat_with_gpt(SYSTEM_PROMPT, transcript) return transcript, reply def main(): """ Launch the Gradio interface. """ iface = gr.Interface( fn=handle_interaction, inputs=gr.Audio(source="microphone", type="filepath", label="Speak to RentBot"), outputs=[ gr.Textbox(label="Transcribed Text"), gr.Textbox(label="RentBot Reply") ], title="RentBot 24/7", description=( "An AI virtual receptionist for property managers, " "built with OpenAI Whisper and GPT-4o-mini." ), allow_flagging="never", analytics_enabled=False ) iface.launch(server_name="0.0.0.0", server_port=7860, share=True) if __name__ == "__main__": main()