Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
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 |
-
|
28 |
completion = client.chat.completions.create(model="gpt-4o-mini",
|
29 |
-
messages=
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
else:
|
34 |
-
|
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 = "
|
45 |
-
submit_window.click(chat, inputs=[prompt_window, user_window, pwd_window
|
46 |
-
|
|
|
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()
|