coach / app.py
ritwikbiswas's picture
added emoji
6334852
import os
import random
import gradio as gr
import openai
team_list=['Ana','Ashe','Baptiste','Bastion','Brigitte','Cassidy','Doomfist','Dva','Echo','Genji','Hanzo','JunkerQueen','Junkrat','Kiriko','Lucio','Mei','Mercy','Moira','Orisa','Pharah','Reaper','Reinhardt','Roadhog','Sigma','Sojourn','Soldier76','Sombra','Symmetra','Torbjorn','Tracer','Widowmaker','Winston','Wrecking Ball','Zarya','Zenyatta','None']
val_team_list=["Astra", "Breach", "Brimstone", "Chamber", "Cypher", "Jett", "Kay", "Killjoy", "Neon", "Omen", "Phoenix", "Raze", "Reyna", "Sage", "Skye", "Sova", "Viper","Yoru","None"]
openai.api_key = os.getenv("OPENAI_API_KEY")
#playing Overwatch as Sombra with Moira on my team, how do I can counter a Pharah,Ashe?"
#Playing Valorant as Jett, how do I counter Omen?
def process_squad(Team):
if len(Team) == 1:
return " "+Team[0]
else:
constructor = ""
for hero in Team:
constructor += f' {hero},'
constructor = constructor[:-1]
return constructor
def chat(Mode, Me, Teammate, Opponents, history):
history = history or []
teammate_string = str(Teammate)
if not Me or Me=="None":
history.append((str(Teammate)+str(Opponents), "Please select the hero you're playing"))
return history, history
print(Me)
message = "Playing Overwatch2 as " + str(Me)
if not Teammate or Teammate == "None":
message += ", "
else:
print(Teammate)
message += f' with {teammate_string} on my team, '
if not Opponents:
message += "how should we play to win games?"
else:
message += f' how do we counter{process_squad(Opponents)}?'
if Mode == "Bronze":
message += " Give sarcastic advice."
response = openai.Completion.create(model="text-davinci-003", prompt=message, temperature=0.7, max_tokens=100)['choices'][0]['text']
index = response.rfind('.')
response = response[:index+1]
if not Teammate or Teammate == "None":
chat_msg = f'{Me} v {",".join(Opponents)}'
else:
chat_msg = f'{Me},{Teammate} v {",".join(Opponents)}'.lower()
print(response)
history.append((chat_msg, response))
return history, history
chatbot = gr.Chatbot().style(color_map=("grey", "blue"))
chatbot2 = gr.Chatbot().style(color_map=("grey", "red"))
def chat2(Mode,Me, Opponent, history):
history = history or []
if not Me or Me=="None":
history.append((str(Opponent), "Please select the agent you're playing"))
return history, history
print(Me)
message = "Playing Valorant as " + str(Me)
if not Opponent or Opponent == "None":
message += ", give advice on playstle."
else:
message += f', how do I counter {Opponent}?'
if Mode == "Bronze":
message += " Give sarcastic advice."
response = openai.Completion.create(model="text-davinci-003", prompt=message, temperature=0.65, max_tokens=100)['choices'][0]['text']
# response = "Coming Soon"
history.append((f'{Me} v {Opponent}', response))
return history, history
chatbot = gr.Chatbot().style(color_map=("grey", "blue"))
demo1 = gr.Interface(
chat,
[
gr.Radio(["Normal", "Bronze"],value="Normal"),
gr.Dropdown(team_list),
gr.Dropdown(team_list),
gr.Dropdown(team_list, value=[team_list[random.randint(1,30)]], multiselect=True),
# gr.Checkbox(label="Is it the morning?"),
"state"
],
[chatbot, "state"],
allow_flagging="never",
#title="GPT-3 Overwatch Coach",
description="Please select the hero you play. Choose less than two other heroes for best advice.",
css="footer {visibility: hidden}"
)
demo2 = gr.Interface(
chat2,
[
gr.Radio(["Normal", "Bronze"],value="Normal"),
gr.Dropdown(val_team_list, value=[]),
gr.Dropdown(val_team_list, value=[val_team_list[random.randint(1,12)]]),
"state"
],
[chatbot2, "state"],
allow_flagging="never",
css="footer {visibility: hidden}"
)
demo = gr.TabbedInterface([demo1, demo2], ["Overwatch 2 Coach", "Valorant Coach"],title="GPT-3 Coaching 🤖",css="footer {visibility: hidden}")
#if __name__ == "__main__":
demo.launch()