dlflannery commited on
Commit
3de8d87
·
verified ·
1 Parent(s): a157f63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -6,8 +6,10 @@ from dotenv import load_dotenv
6
 
7
  load_dotenv()
8
  key = os.getenv('OPENAI_API_KEY')
9
- uname = os.getenv('LOGNAME')
10
- pwd = os.getenv('PASSWORD')
 
 
11
 
12
  client = OpenAI(api_key = key)
13
 
@@ -15,10 +17,10 @@ def clear():
15
  return [None, [], None]
16
 
17
  def updatePassword(txt):
18
- return [txt, None]
19
 
20
  def chat(prompt, user_window, pwd_window, past, response, gptModel):
21
- if user_window==uname and pwd_window==pwd:
22
  past.append({"role":"user", "content":prompt})
23
  completion = client.chat.completions.create(model=gptModel,
24
  messages=past)
@@ -27,9 +29,9 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel):
27
  if len(response) > 40000:
28
  response += "\n\nTHIS DIALOG IS GETTING TOO LONG. PLEASE CLEAR IT."
29
  past.append({"role":"assistant", "content": reply})
30
- return [past, response, None, None]
31
  else:
32
- return [[], "User name and/or password are incorrect", prompt, pwd_window]
33
 
34
  with gr.Blocks() as demo:
35
  history = gr.State([])
@@ -43,14 +45,14 @@ with gr.Blocks() as demo:
43
  pwd_window = gr.Textbox(label = "Password")
44
  pwd_window.blur(updatePassword, pwd_window, [password, pwd_window])
45
  with gr.Row():
46
- clear_button = gr.Button(value="Clear Dialog")
47
  gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
48
  value="gpt-3.5-turbo", label="GPT Model", interactive=True)
49
  submit_window = gr.Button(value="Submit Prompt/Question")
50
  prompt_window = gr.Textbox(label = "Prompt or Question")
51
  output_window = gr.Textbox(label = "Dialog")
52
  submit_window.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
53
- outputs=[history, output_window, prompt_window, pwd_window])
54
  clear_button.click(clear, inputs=[], outputs=[prompt_window, history, output_window])
55
 
56
  demo.launch()
 
6
 
7
  load_dotenv()
8
  key = os.getenv('OPENAI_API_KEY')
9
+ users = os.getenv('LOGNAME')
10
+ unames = users.split(',')
11
+ pwds = os.getenv('PASSWORD')
12
+ pwdList = pwds.split(',')
13
 
14
  client = OpenAI(api_key = key)
15
 
 
17
  return [None, [], None]
18
 
19
  def updatePassword(txt):
20
+ return [txt, "*********"]
21
 
22
  def chat(prompt, user_window, pwd_window, past, response, gptModel):
23
+ if user_window in unames and pwd_window in pwdList:
24
  past.append({"role":"user", "content":prompt})
25
  completion = client.chat.completions.create(model=gptModel,
26
  messages=past)
 
29
  if len(response) > 40000:
30
  response += "\n\nTHIS DIALOG IS GETTING TOO LONG. PLEASE CLEAR IT."
31
  past.append({"role":"assistant", "content": reply})
32
+ return [past, response, None]
33
  else:
34
+ return [[], "User name and/or password are incorrect", prompt]
35
 
36
  with gr.Blocks() as demo:
37
  history = gr.State([])
 
45
  pwd_window = gr.Textbox(label = "Password")
46
  pwd_window.blur(updatePassword, pwd_window, [password, pwd_window])
47
  with gr.Row():
48
+ clear_button = gr.Button(value="Restart Conversation")
49
  gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
50
  value="gpt-3.5-turbo", label="GPT Model", interactive=True)
51
  submit_window = gr.Button(value="Submit Prompt/Question")
52
  prompt_window = gr.Textbox(label = "Prompt or Question")
53
  output_window = gr.Textbox(label = "Dialog")
54
  submit_window.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
55
+ outputs=[history, output_window, prompt_window])
56
  clear_button.click(clear, inputs=[], outputs=[prompt_window, history, output_window])
57
 
58
  demo.launch()