ritwikbiswas commited on
Commit
523a66c
1 Parent(s): 3cadb7f

init comit

Browse files
Files changed (2) hide show
  1. app.py +113 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import gradio as gr
4
+ import openai
5
+
6
+ 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']
7
+
8
+ val_team_list=["Astra", "Breach", "Brimstone", "Chamber", "Cypher", "Jett", "Kay", "Killjoy", "Neon", "Omen", "Phoenix", "Raze", "Reyna", "Sage", "Skye", "Sova", "Viper","Yoru","None"]
9
+
10
+
11
+ openai.api_key = os.getenv("OPENAI_API_KEY")
12
+ #playing Overwatch as Sombra with Moira on my team, how do I can counter a Pharah,Ashe?"
13
+ #Playing Valorant as Jett, how do I counter Omen?
14
+
15
+ def process_squad(Team):
16
+ if len(Team) == 1:
17
+ return " "+Team[0]
18
+ else:
19
+ constructor = ""
20
+ for hero in Team:
21
+ constructor += f' {hero},'
22
+ constructor = constructor[:-1]
23
+ return constructor
24
+
25
+ def chat(Mode, Me, Teammate, Opponents, history):
26
+ history = history or []
27
+ teammate_string = str(Teammate)
28
+ if not Me or Me=="None":
29
+ history.append((str(Teammate)+str(Opponents), "Please select the hero you're playing"))
30
+ return history, history
31
+ print(Me)
32
+ message = "Playing Overwatch2 as " + str(Me)
33
+
34
+ if not Teammate or Teammate == "None":
35
+ message += ", "
36
+ else:
37
+ print(Teammate)
38
+ message += f' with {teammate_string} on my team, '
39
+ if not Opponents:
40
+ message += "how should I play to win games?"
41
+ else:
42
+ message += f' how do we counter{process_squad(Opponents)}?'
43
+ if Mode == "Bronze":
44
+ message += " Give sarcastic advice."
45
+
46
+ response = openai.Completion.create(model="text-davinci-003", prompt=message, temperature=0.7, max_tokens=100)['choices'][0]['text']
47
+ index = response.rfind('.')
48
+ response = response[:index+1]
49
+
50
+ if not Teammate or Teammate == "None":
51
+ chat_msg = f'{Me} v {",".join(Opponents)}'
52
+ else:
53
+ chat_msg = f'{Me},{Teammate} v {",".join(Opponents)}'.lower()
54
+ print(response)
55
+ history.append((chat_msg, response))
56
+ return history, history
57
+
58
+ chatbot = gr.Chatbot().style(color_map=("grey", "blue"))
59
+ chatbot2 = gr.Chatbot().style(color_map=("grey", "red"))
60
+
61
+ def chat2(Mode,Me, Opponent, history):
62
+ history = history or []
63
+ if not Me or Me=="None":
64
+ history.append((str(Opponent), "Please select the agent you're playing"))
65
+ return history, history
66
+ print(Me)
67
+ message = "Playing Valorant as " + str(Me)
68
+
69
+ if not Opponent or Opponent == "None":
70
+ message += ", give advice on playstle."
71
+ else:
72
+ message += f', how do I counter {Opponent}?'
73
+ if Mode == "Bronze":
74
+ message += " Give sarcastic advice."
75
+ response = openai.Completion.create(model="text-davinci-003", prompt=message, temperature=0.65, max_tokens=100)['choices'][0]['text']
76
+ # response = "Coming Soon"
77
+ history.append((f'{Me} v {Opponent}', response))
78
+ return history, history
79
+
80
+ chatbot = gr.Chatbot().style(color_map=("grey", "blue"))
81
+
82
+ demo1 = gr.Interface(
83
+ chat,
84
+ [
85
+ gr.Radio(["Normal", "Bronze"],value="Normal"),
86
+ gr.Dropdown(team_list),
87
+ gr.Dropdown(team_list),
88
+ gr.Dropdown(team_list, value=[team_list[random.randint(1,30)]], multiselect=True),
89
+ # gr.Checkbox(label="Is it the morning?"),
90
+ "state"
91
+ ],
92
+ [chatbot, "state"],
93
+ allow_flagging="never",
94
+ #title="GPT-3 Overwatch Coach",
95
+ description="Please select the hero you play. Choose less than two other heroes for best advice.",
96
+ css="footer {visibility: hidden}"
97
+ )
98
+
99
+ demo2 = gr.Interface(
100
+ chat2,
101
+ [
102
+ gr.Radio(["Normal", "Bronze"],value="Normal"),
103
+ gr.Dropdown(val_team_list, value=[]),
104
+ gr.Dropdown(val_team_list, value=[val_team_list[random.randint(1,12)]]),
105
+ "state"
106
+ ],
107
+ [chatbot2, "state"],
108
+ allow_flagging="never",
109
+ css="footer {visibility: hidden}"
110
+ )
111
+ demo = gr.TabbedInterface([demo1, demo2], ["Overwatch 2 Coach", "Valorant Coach"],title="GPT-3 Game Coaching",css="footer {visibility: hidden}")
112
+ #if __name__ == "__main__":
113
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai