dlflannery commited on
Commit
3b847a5
·
verified ·
1 Parent(s): d67b0e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -10,39 +10,34 @@ uname = os.getenv('LOGNAME')
10
  pwd = os.getenv('PASSWORD')
11
 
12
  client = OpenAI(api_key = key)
13
- history = []
14
- dialog = "Transcript:"
15
 
16
  def clear():
17
- global history
18
- global dialog
19
- history=[]
20
- dialog = "Transcript:"
21
- return [None, None]
22
 
23
- def chat(prompt, user_window, pwd_window):
24
- global history
25
- global dialog
26
  if user_window==uname and pwd_window==pwd:
27
- history.append({"role":"user", "content":prompt})
28
  completion = client.chat.completions.create(model="gpt-4o-mini",
29
- messages=history)
30
- dialog += "\n\nYOU: " + prompt + "\nGPT: " + completion.choices[0].message.content
31
- result = dialog
32
- history.append(({"role":"assistant", "content":result}))
 
33
  else:
34
- result = "User name and/or password are incorrect"
35
- return result
36
 
37
  with gr.Blocks() as demo:
 
 
38
  heading = gr.Label(value="GPT Chat", scale=2, color="Crimson" )
39
  user_window = gr.Textbox(label = "User Name")
40
  pwd_window = gr.Textbox(label = "Password")
41
  clear_button = gr.Button(value="Clear")
42
  prompt_window = gr.Textbox(label = "Prompt")
43
  submit_window = gr.Button(value="Submit")
44
- output_window = gr.Textbox(label = "Response")
45
- submit_window.click(chat, inputs=[prompt_window, user_window, pwd_window], outputs=output_window)
46
- clear_button.click(clear, inputs=[], outputs=[prompt_window, output_window])
 
47
 
48
  demo.launch()
 
10
  pwd = os.getenv('PASSWORD')
11
 
12
  client = OpenAI(api_key = key)
 
 
13
 
14
  def clear():
15
+ return [None, [], None]
 
 
 
 
16
 
17
+ def chat(prompt, user_window, pwd_window, past, response):
 
 
18
  if user_window==uname and pwd_window==pwd:
19
+ past.append({"role":"user", "content":prompt})
20
  completion = client.chat.completions.create(model="gpt-4o-mini",
21
+ messages=past)
22
+ reply = completion.choices[0].message.content
23
+ response += "\n\nYOU: " + prompt + "\nGPT: " + reply
24
+ past.append({"role":"assistant", "content": reply})
25
+ return [past, response]
26
  else:
27
+ return [[], "User name and/or password are incorrect"]
 
28
 
29
  with gr.Blocks() as demo:
30
+ history = gr.State([])
31
+ dialog = gr.State()
32
  heading = gr.Label(value="GPT Chat", scale=2, color="Crimson" )
33
  user_window = gr.Textbox(label = "User Name")
34
  pwd_window = gr.Textbox(label = "Password")
35
  clear_button = gr.Button(value="Clear")
36
  prompt_window = gr.Textbox(label = "Prompt")
37
  submit_window = gr.Button(value="Submit")
38
+ output_window = gr.Textbox(label = "Dialog")
39
+ submit_window.click(chat, inputs=[prompt_window, user_window, pwd_window, history, output_window],
40
+ outputs=[history, output_window])
41
+ clear_button.click(clear, inputs=[], outputs=[prompt_window, history, output_window])
42
 
43
  demo.launch()