File size: 4,220 Bytes
523a66c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 I 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 Game Coaching",css="footer {visibility: hidden}")
#if __name__ == "__main__":
demo.launch()