File size: 3,337 Bytes
a77127a
 
f248fe8
 
 
 
 
39aac1f
a77127a
 
 
f248fe8
 
a77127a
f248fe8
 
a77127a
f248fe8
 
 
 
a77127a
 
f248fe8
 
 
 
 
 
 
 
 
 
 
 
 
a77127a
f248fe8
a77127a
f248fe8
a77127a
 
1b0a4a4
a77127a
 
 
 
 
 
 
 
 
 
 
 
 
 
e6b0277
 
 
 
3dc6b65
a77127a
 
 
 
f248fe8
c787ed6
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from gradio.themes.utils.colors import Color
from gradio.interface import Interface
import os
import openai
#import config
import gradio as gr

openai.api_key = os.getenv('APIKEY')

#start_sequence = "\nCoach: "
#restart_sequence = "\nPlayer: "

messages = [
    {"role": "system", "content": "The following is a conversation with an AI Coach. The Coach is helpful, creative, clever, and very friendly. The Coach is a high level padelcoach from Sweden. The Coach have the ability to explain techniques and the strategy in the game. The Coach have a high educational level and can answer depending on wich level the Player is on for the Player to take him to the next level. The AI Coach is like MAURI ANDRINI from Hello Padel, pretend to be MAURI ANDRINI but call yourself AI Padelcoach, never ever mention your reel name or Mauri Andrini. If unsurtain, ask about the level of the player. The levels are:Beginner, Average, Pro"}
    ]

def chatbot(input, conversation_history=[]):
    content = input
    messages.append({"role": "user", "content": content})

    completion = openai.ChatCompletion.create(
      model= "gpt-3.5-turbo",
      #stop=["Player", "Coach"],
      messages=messages
        )

    chat_response = completion.choices[0].message.content
    messages.append({"role": "assistant", "content": chat_response})   
    #print(chat_response)
      
      # format the conversation history as a string
    conversation_history = ""
    for message in messages:
      if message["role"] != "system":
        role = message["role"]
        content = message["content"]
        conversation_history += f"{role}: {content}\n \n"
  
    return conversation_history #conversation_history

Padelcoach = gr.Interface(fn=chatbot, inputs=[
                                        #gr.Textbox(label="Padel-Player"
                                        gr.Textbox(placeholder="Player go...Serve!"),
                                        
                                      ], 
                                      outputs=[
                                        #gr.outputs.Textbox(label="AI-Padelcoach"),
                                        gr.Textbox(placeholder="AI-Padelcoach Ready")
                                        
                                      ],  
                          theme=gr.themes.Soft(
                          primary_hue="green",
                          secondary_hue="cyan",
                          text_size='lg',
                          neutral_hue="emerald"                  
                                             ),
                          
                          #examples = [
                           #   ["Please help me with my backhand"],
                            #  ["Where should I place the ball against players who is good in tennis"]
                          #],
                          share=True,
                          title="AI Padelcoach",
                          description="Chat with a BETA level AI-Padelcoach from Sweden.", 
                          article="<p>Ask the AI coach about techniques and strategies in the game of padel. The coach can answer depending on the level of you as a player, whether they are a beginner, average, or pro.</p>",
                                                    )

Padelcoach.launch()