File size: 1,398 Bytes
9b9cf11
 
 
18a747d
 
 
 
 
9b9cf11
 
18a747d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient



client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct") #I had errors with quite a few of the models but this one was sucessful



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, #increased to make sure nothing gets cut off
       temperature = .2, #playing around with this, I got very strange responses when it was too high
       frequency_penalty = 1, #trying this to limit repetition
       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)