Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,32 +14,43 @@ client = OpenAI(api_key = key)
|
|
| 14 |
def clear():
|
| 15 |
return [None, [], None]
|
| 16 |
|
| 17 |
-
def
|
|
|
|
|
|
|
|
|
|
| 18 |
if user_window==uname and pwd_window==pwd:
|
| 19 |
past.append({"role":"user", "content":prompt})
|
| 20 |
-
completion = client.chat.completions.create(model=
|
| 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 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
with gr.Row():
|
| 34 |
user_window = gr.Textbox(label = "User Name")
|
| 35 |
pwd_window = gr.Textbox(label = "Password")
|
|
|
|
| 36 |
with gr.Row():
|
| 37 |
-
clear_button = gr.Button(value="Clear")
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
| 40 |
output_window = gr.Textbox(label = "Dialog")
|
| 41 |
-
submit_window.click(chat, inputs=[prompt_window, user_window,
|
| 42 |
-
outputs=[history, output_window])
|
| 43 |
clear_button.click(clear, inputs=[], outputs=[prompt_window, history, output_window])
|
| 44 |
|
| 45 |
demo.launch()
|
|
|
|
| 14 |
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)
|
| 25 |
reply = completion.choices[0].message.content
|
| 26 |
response += "\n\nYOU: " + prompt + "\nGPT: " + reply
|
| 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([])
|
| 36 |
+
password = gr.State("")
|
| 37 |
+
model = gr.State("gpt-3.5-turbo")
|
| 38 |
+
gr.Markdown('# GPT Chat')
|
| 39 |
+
gr.Markdown('Enter user name & password then enter prompt and click submit button. GPT 3.5 is cheaper but GPT 4o may perform better.')
|
| 40 |
+
# heading = gr.Label(value="GPT Chat", scale=2, color="Crimson" )
|
| 41 |
with gr.Row():
|
| 42 |
user_window = gr.Textbox(label = "User Name")
|
| 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()
|