Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,8 @@ from dotenv import load_dotenv
|
|
6 |
|
7 |
load_dotenv()
|
8 |
key = os.getenv('OPENAI_API_KEY')
|
9 |
-
|
10 |
-
|
11 |
|
12 |
client = OpenAI(api_key = key)
|
13 |
|
@@ -15,23 +15,24 @@ def clear():
|
|
15 |
return [None, None]
|
16 |
|
17 |
|
18 |
-
def chat(prompt):
|
19 |
-
|
|
|
20 |
messages=[{"role":"user", "content":prompt}])
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
return result
|
25 |
|
26 |
with gr.Blocks() as demo:
|
27 |
heading = gr.Label(value="GPT Chat", scale=2, color="Crimson" )
|
28 |
-
|
29 |
-
|
30 |
clear_button = gr.Button(value="Clear")
|
31 |
prompt_window = gr.Textbox(label = "Prompt")
|
32 |
submit_window = gr.Button(value="Submit")
|
33 |
output_window = gr.Textbox(label = "Response")
|
34 |
-
submit_window.click(chat, inputs=[prompt_window], outputs=output_window)
|
35 |
clear_button.click(clear, inputs=[], outputs=[prompt_window, output_window])
|
36 |
|
37 |
-
demo.launch(
|
|
|
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 |
return [None, None]
|
16 |
|
17 |
|
18 |
+
def chat(prompt, user_window, pwd_window):
|
19 |
+
if user_window==uname and pwd_window==pwd:
|
20 |
+
completion = client.chat.completions.create(model="gpt-4o-mini",
|
21 |
messages=[{"role":"user", "content":prompt}])
|
22 |
+
result = completion.choices[0].message.content
|
23 |
+
else:
|
24 |
+
result = "User name and/or password are incorrect"
|
25 |
return result
|
26 |
|
27 |
with gr.Blocks() as demo:
|
28 |
heading = gr.Label(value="GPT Chat", scale=2, color="Crimson" )
|
29 |
+
user_window = gr.Textbox(label = "User Name")
|
30 |
+
pwd_window = gr.Textbox(label = "Password")
|
31 |
clear_button = gr.Button(value="Clear")
|
32 |
prompt_window = gr.Textbox(label = "Prompt")
|
33 |
submit_window = gr.Button(value="Submit")
|
34 |
output_window = gr.Textbox(label = "Response")
|
35 |
+
submit_window.click(chat, inputs=[prompt_window, user_window, pwd_window], outputs=output_window)
|
36 |
clear_button.click(clear, inputs=[], outputs=[prompt_window, output_window])
|
37 |
|
38 |
+
demo.launch()
|