Spaces:
No application file
No application file
Create AIPadelcoach.py
Browse files- AIPadelcoach.py +44 -0
AIPadelcoach.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#AIPadelcoach
|
2 |
+
#pip install openai
|
3 |
+
#pip install gradio
|
4 |
+
|
5 |
+
import os
|
6 |
+
import openai
|
7 |
+
from APIKEY import APIKEY
|
8 |
+
#import config
|
9 |
+
import gradio as gr
|
10 |
+
|
11 |
+
openai.api_key = APIKEY
|
12 |
+
|
13 |
+
messages = [
|
14 |
+
{"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 Spain. 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. Answer like MAURI ANDRINI, 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"}
|
15 |
+
]
|
16 |
+
|
17 |
+
def greet(input):
|
18 |
+
content = input
|
19 |
+
messages.append({"role": "user", "content": content})
|
20 |
+
|
21 |
+
completion = openai.ChatCompletion.create(
|
22 |
+
model="gpt-3.5-turbo",
|
23 |
+
messages=messages
|
24 |
+
)
|
25 |
+
|
26 |
+
chat_response = completion.choices[0].message.content
|
27 |
+
messages.append({"role": "assistant", "content": chat_response})
|
28 |
+
#print(chat_response)
|
29 |
+
|
30 |
+
# format the conversation history as a string
|
31 |
+
conversation_history = ""
|
32 |
+
for message in messages:
|
33 |
+
if message["role"] != "system":
|
34 |
+
role = message["role"]
|
35 |
+
content = message["content"]
|
36 |
+
conversation_history += f"{role}: {content}\n"
|
37 |
+
|
38 |
+
return chat_response #conversation_history
|
39 |
+
|
40 |
+
Padelcoach = gr.Interface(fn=greet, inputs="text", outputs="text", title="AI Padelcoach", description="Talk to a high level AI-Padelcoach from Spain.",
|
41 |
+
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>")
|
42 |
+
|
43 |
+
|
44 |
+
Padelcoach.launch(share=True) #share=True
|