Spaces:
Sleeping
Sleeping
Changed login
Browse files
app.py
CHANGED
|
@@ -20,14 +20,6 @@ with demo:
|
|
| 20 |
## Title
|
| 21 |
gr.Markdown('# Chat Quest!', elem_id='gradio_center')
|
| 22 |
|
| 23 |
-
input_openai_key = gr.Textbox(
|
| 24 |
-
label='Para jugar necesitás una API key de OpenAI.',
|
| 25 |
-
placeholder='sk-********************',
|
| 26 |
-
type='password',
|
| 27 |
-
interactive=True,
|
| 28 |
-
autofocus=True
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
with gr.Column(variant='panel'):
|
| 32 |
## Header
|
| 33 |
with gr.Row(variant='default'):
|
|
@@ -49,7 +41,8 @@ with demo:
|
|
| 49 |
)
|
| 50 |
|
| 51 |
situation_goal = gr.Markdown(format_goal_messsage(sample_conversation.goal_message))
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
with gr.Column(variant='panel', visible=False) as outcome_won:
|
|
@@ -87,14 +80,10 @@ with demo:
|
|
| 87 |
queue=False
|
| 88 |
)
|
| 89 |
|
| 90 |
-
input_openai_key.submit(
|
| 91 |
-
update_openai_key,
|
| 92 |
-
inputs=[input_openai_key],
|
| 93 |
-
outputs=[input_openai_key]
|
| 94 |
-
)
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
demo.launch(
|
| 98 |
server_port=None,
|
|
|
|
| 99 |
max_threads=4, show_api=False, share=False
|
| 100 |
)
|
|
|
|
| 20 |
## Title
|
| 21 |
gr.Markdown('# Chat Quest!', elem_id='gradio_center')
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
with gr.Column(variant='panel'):
|
| 24 |
## Header
|
| 25 |
with gr.Row(variant='default'):
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
situation_goal = gr.Markdown(format_goal_messsage(sample_conversation.goal_message))
|
| 44 |
+
|
| 45 |
+
choice_buttons = [gr.Button(e, min_width=10) for e in sample_conversation.starting_choices]
|
| 46 |
|
| 47 |
|
| 48 |
with gr.Column(variant='panel', visible=False) as outcome_won:
|
|
|
|
| 80 |
queue=False
|
| 81 |
)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
if __name__ == "__main__":
|
| 85 |
demo.launch(
|
| 86 |
server_port=None,
|
| 87 |
+
auth=validate_auth,
|
| 88 |
max_threads=4, show_api=False, share=False
|
| 89 |
)
|
utils.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
import time
|
| 4 |
from chat_quest import sample_conversation, sample_conversation_christmas, generate_chat_response, generate_last_response, ConversationSituation, N_CHOICES
|
| 5 |
|
| 6 |
|
|
@@ -69,14 +68,12 @@ def load_next_level():
|
|
| 69 |
|
| 70 |
opponent_name = format_chat_header(new_situation.character)
|
| 71 |
goal_message = format_goal_messsage(new_situation.goal_message)
|
| 72 |
-
|
| 73 |
|
| 74 |
return choices_update + [new_situation, new_situation.starting_choices, outcome_update, chat_history_update, chat_history_update] + [new_situation.character_emoji, opponent_name, goal_message, False]
|
| 75 |
|
| 76 |
|
| 77 |
def process_key(openai_key: str):
|
| 78 |
import os
|
| 79 |
-
|
| 80 |
result = openai_key
|
| 81 |
|
| 82 |
if openai_key.lower() == os.environ.get('USER'):
|
|
@@ -89,18 +86,16 @@ def validate_openai_key(password: str):
|
|
| 89 |
return password.startswith("sk-")
|
| 90 |
|
| 91 |
|
| 92 |
-
def
|
| 93 |
import openai
|
| 94 |
|
| 95 |
-
processed_pw = process_key(
|
| 96 |
is_valid_login = validate_openai_key(processed_pw)
|
| 97 |
|
| 98 |
if is_valid_login:
|
| 99 |
openai.api_key = processed_pw
|
| 100 |
-
else:
|
| 101 |
-
gr.Warning("Not a valid password")
|
| 102 |
|
| 103 |
-
return
|
| 104 |
|
| 105 |
|
| 106 |
def _format_dialogue(dialogue_list, opponent):
|
|
@@ -111,4 +106,4 @@ def _format_dialogue(dialogue_list, opponent):
|
|
| 111 |
formatted_dialogue.append(f"{opponent}: {opponent_line}")
|
| 112 |
if player_line:
|
| 113 |
formatted_dialogue.append(f"Player: {player_line}")
|
| 114 |
-
return '\n'.join(formatted_dialogue)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
| 3 |
from chat_quest import sample_conversation, sample_conversation_christmas, generate_chat_response, generate_last_response, ConversationSituation, N_CHOICES
|
| 4 |
|
| 5 |
|
|
|
|
| 68 |
|
| 69 |
opponent_name = format_chat_header(new_situation.character)
|
| 70 |
goal_message = format_goal_messsage(new_situation.goal_message)
|
|
|
|
| 71 |
|
| 72 |
return choices_update + [new_situation, new_situation.starting_choices, outcome_update, chat_history_update, chat_history_update] + [new_situation.character_emoji, opponent_name, goal_message, False]
|
| 73 |
|
| 74 |
|
| 75 |
def process_key(openai_key: str):
|
| 76 |
import os
|
|
|
|
| 77 |
result = openai_key
|
| 78 |
|
| 79 |
if openai_key.lower() == os.environ.get('USER'):
|
|
|
|
| 86 |
return password.startswith("sk-")
|
| 87 |
|
| 88 |
|
| 89 |
+
def validate_auth(user: str, pw: str) -> bool:
|
| 90 |
import openai
|
| 91 |
|
| 92 |
+
processed_pw = process_key(pw)
|
| 93 |
is_valid_login = validate_openai_key(processed_pw)
|
| 94 |
|
| 95 |
if is_valid_login:
|
| 96 |
openai.api_key = processed_pw
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
return is_valid_login
|
| 99 |
|
| 100 |
|
| 101 |
def _format_dialogue(dialogue_list, opponent):
|
|
|
|
| 106 |
formatted_dialogue.append(f"{opponent}: {opponent_line}")
|
| 107 |
if player_line:
|
| 108 |
formatted_dialogue.append(f"Player: {player_line}")
|
| 109 |
+
return '\n'.join(formatted_dialogue)
|