Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import asyncio
|
| 5 |
+
from utils import init_openai, transcribe_audio, chat_with_gpt
|
| 6 |
+
|
| 7 |
+
# Initialize OpenAI key
|
| 8 |
+
default_system_prompt = (
|
| 9 |
+
"You are RentBot, a friendly virtual leasing assistant. "
|
| 10 |
+
"Answer inquiries about rental listings, schedule showings, and provide clear instructions to potential tenants."
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
init_openai()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def handle_interaction(audio):
|
| 17 |
+
# Save incoming audio
|
| 18 |
+
audio_path = "input.wav"
|
| 19 |
+
audio.save(audio_path)
|
| 20 |
+
|
| 21 |
+
# Transcribe
|
| 22 |
+
text = asyncio.run(transcribe_audio(audio_path))
|
| 23 |
+
|
| 24 |
+
# Chat
|
| 25 |
+
reply = asyncio.run(chat_with_gpt(default_system_prompt, text))
|
| 26 |
+
return text, reply
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=handle_interaction,
|
| 30 |
+
inputs=gr.Audio(source="microphone", type="filepath", label="Speak to RentBot"),
|
| 31 |
+
outputs=[
|
| 32 |
+
gr.Textbox(label="Transcribed Text"),
|
| 33 |
+
gr.Textbox(label="RentBot Reply")
|
| 34 |
+
],
|
| 35 |
+
title="RentBot 24/7",
|
| 36 |
+
description="An AI virtual receptionist for property managers, built with OpenAI Whisper and ChatGPT."
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|