Spaces:
Sleeping
Sleeping
Download app/app.py from PersonaMusicGroup/PersonaAI: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/PersonaMusicGroup/PersonaAI/resolve/main/app/app.py
- Command line
-
hf download hf://spaces/PersonaMusicGroup/PersonaAI/app/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PersonaMusicGroup/PersonaAI/resolve/main/app/app.py
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 | |
| 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() | |