PersonaAI / app /app.py
Vemel's picture
Use dataclasses instead of dicts, added integration readme note
6cc7dfa unverified
Raw History Blame Contribute Delete
1.65 kB
import uuid
from typing import Any
import gradio as gr
from dotenv import load_dotenv
from app.langchain_agent import llm_inference
from app.logger import get_logger
from app.utils import timing
@timing
def predict_interface(message: str, history: Any = None, user_id: str = "user") -> str:
response = llm_inference(message, user_id)
return response.output
def create_chat() -> gr.ChatInterface:
session_id = gr.Textbox(value=str(uuid.uuid4()), type="text", label="session_id")
example_sentences = [
"Recommend me something in Quentin Tarantino reggae style",
"Give me songs with calm and relaxing vibes",
"I want to listen to something like the movie Inception",
"I want music that sounds like Lebron James eating soup",
]
examples = [[example, f"user_{i}"] for i, example in enumerate(example_sentences)]
return gr.ChatInterface(
predict_interface,
additional_inputs=[session_id],
chatbot=gr.Chatbot(height=600),
textbox=gr.Textbox(
placeholder="Ask me for music recommendations!", container=False, scale=7
),
description="This AI makes song recommendations based on your music style.",
examples=examples,
title="Persona Music song recommender",
retry_btn="Retry",
clear_btn="Clear",
undo_btn=None,
)
def main():
logger = get_logger()
load_dotenv(override=True, verbose=True, dotenv_path=".env")
logger.info("Running chat")
chat = create_chat()
chat.queue().launch(server_name="0.0.0.0", server_port=7860, share=False)
if __name__ == "__main__":
main()