Spaces:
PhilSpiel
/
Running

PhilSpiel commited on
Commit
8c57ca0
1 Parent(s): fab964d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -65
app.py CHANGED
@@ -18,15 +18,11 @@ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
18
  openai_model = "gpt-3.5-turbo-0125"
19
  ################# End OpenAI-SPECIFIC VALUES ######################
20
 
21
- ################# Log in ######################
22
- security = os.getenv("AUTH")
23
-
24
  ############### CHAT ###################
25
  def predict(user_input, history):
26
  max_length = 500
27
  if len(user_input) > max_length:
28
  raise gr.Error(f"Input is TOO LONG. Max length is {max_length} characters. Try again.")
29
-
30
  history_openai_format = [
31
  {"role": "system", "content": "IDENTITY: " + sys_prompt_new}
32
  ]
@@ -53,67 +49,8 @@ def predict(user_input, history):
53
 
54
  return message_content
55
 
56
- def same_auth(username, password):
57
- username = username + security
58
- return username == password
59
-
60
- def get_user_summary(name):
61
- return "Welcome, " + name + ". Please proceed to the '" + coach_name_long + "' tab (above) to chat."
62
-
63
  #GUI
64
  theme = gr.themes.Default()
65
-
66
- with gr.Blocks() as demo:
67
- output_choice = gr.State('Text') # Set 'Text' as the default state value
68
-
69
- with gr.Tabs() as tabs:
70
- with gr.TabItem("Log In"):
71
- username_input = gr.Textbox(label="Username (REQUIRED):", placeholder="Enter your USERNAME", type="text")
72
- password_input = gr.Textbox(label="Emailed Code (REQUIRED):", placeholder="Enter CODE from your email", type="password")
73
-
74
- # The submit_name function will expect two inputs
75
- def submit_name(name, password):
76
- name = name + security
77
- name_upper = name.upper()
78
- pwd = password.upper()
79
- if name_upper != pwd:
80
- name = "NOTLOGGEDIN"
81
- raise gr.Error(f"You must be LOGGED IN to Chat. Refresh the page, log in, and try again.")
82
- if name_upper == "":
83
- name = "NOTLOGGEDIN"
84
- raise gr.Error(f"You must be LOGGED IN to Chat. Refresh the page, log in, and try again.")
85
- else:
86
- name_upper = name_upper[:-4]
87
- name = name[:-4]
88
- return get_user_summary(name)
89
-
90
-
91
- submit_name_button = gr.Button("Log in")
92
- # status_text = gr.Label(label="", container=False)
93
- status_text = gr.Label()
94
- # status_text = gr.Textbox(value="", lines=2, label='', visible=True, interactive=False, autoscroll=False)
95
-
96
- submit_name_button.click(
97
- fn=submit_name,
98
- inputs=[username_input, password_input],
99
- outputs=[status_text]
100
- )
101
-
102
- # Attach submit event to both the username and password fields
103
- username_input.submit(
104
- fn=submit_name,
105
- inputs=[username_input, password_input],
106
- outputs=[status_text]
107
- )
108
-
109
- # Make sure this is done for the password field as well
110
- password_input.submit(
111
- fn=submit_name,
112
- inputs=[username_input, password_input],
113
- outputs=[status_text]
114
- )
115
-
116
- with gr.TabItem(coach_name_long):
117
- gr.ChatInterface(predict, submit_btn="Chat with "+ coach_name_short, retry_btn=None, undo_btn=None, clear_btn=None)
118
-
119
  demo.launch(show_api=False)
 
18
  openai_model = "gpt-3.5-turbo-0125"
19
  ################# End OpenAI-SPECIFIC VALUES ######################
20
 
 
 
 
21
  ############### CHAT ###################
22
  def predict(user_input, history):
23
  max_length = 500
24
  if len(user_input) > max_length:
25
  raise gr.Error(f"Input is TOO LONG. Max length is {max_length} characters. Try again.")
 
26
  history_openai_format = [
27
  {"role": "system", "content": "IDENTITY: " + sys_prompt_new}
28
  ]
 
49
 
50
  return message_content
51
 
 
 
 
 
 
 
 
52
  #GUI
53
  theme = gr.themes.Default()
54
+ with gr.Blocks(theme) as demo:
55
+ gr.ChatInterface(predict, submit_btn="Chat with "+ coach_name_short, retry_btn=None, undo_btn=None, clear_btn=None, autofocus=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  demo.launch(show_api=False)