File size: 1,537 Bytes
51deb94 189726b 51deb94 189726b 51deb94 189726b 51deb94 189726b 51deb94 189726b 51deb94 189726b | 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 55 | 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() |