| import gradio as gr |
| from huggingface_hub import InferenceClient |
|
|
|
|
|
|
| client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct") |
|
|
|
|
|
|
| def respond(message, history): |
| messages = [{"role": "system", "content": "You are an expert in music and your job is to give song reccomendations. You should prompt the user to give you their current favorite songs. You will respond with 3 song recommendations for them to listen to next including the song title and artist."}] |
| |
| if history: |
| messages.extend(history) |
| |
| messages.append({"role": "user", "content": message}) |
| |
| response = client.chat_completion( |
| messages, |
| max_tokens= 900, |
| temperature = .2, |
| frequency_penalty = 1, |
| stream = True |
| ) |
| response_text = "" |
| for message in response: |
| if not message.choices: |
| continue |
| token = message.choices[0].delta.content |
| if token is None: |
| continue |
| response_text += token |
| yield response_text |
| |
| chatbot = gr.ChatInterface(respond, title = "Song Recommender", description ="Tell the songs you like and find your next listens!") |
|
|
|
|
|
|
| chatbot.launch(share=True, debug=True) |
|
|
|
|