Commit
·
80cf518
1
Parent(s):
ceca68f
delete instructor tab
Browse files
app.py
CHANGED
@@ -32,99 +32,73 @@ with gr.Blocks() as demo:
|
|
32 |
#initialize tutor (with state)
|
33 |
study_tutor = gr.State(SlightlyDelusionalTutor())
|
34 |
|
35 |
-
# Student interface
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
## Chat with the Model
|
41 |
-
Description here
|
42 |
-
""")
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
with gr.
|
67 |
-
gr.
|
68 |
-
## Export Your Chat History
|
69 |
-
Export your chat history as a .json, .txt, or .csv file
|
70 |
-
""")
|
71 |
with gr.Row():
|
72 |
-
|
73 |
-
|
74 |
-
export_dialogue_button_csv = gr.Button("CSV")
|
75 |
-
|
76 |
-
file_download = gr.Files(label="Download here", file_types=['.json', '.txt', '.csv'], type="file", visible=False)
|
77 |
-
|
78 |
-
export_dialogue_button_json.click(save_json, study_tutor, file_download, show_progress=True)
|
79 |
-
export_dialogue_button_txt.click(save_txt, study_tutor, file_download, show_progress=True)
|
80 |
-
export_dialogue_button_csv.click(save_csv, study_tutor, file_download, show_progress=True)
|
81 |
|
82 |
-
#
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
"""
|
90 |
-
api_input = gr.Textbox(show_label=False, type="password", visible=False, value=os.environ.get("OPENAI_API_KEY"))
|
91 |
-
|
92 |
-
# Upload secret prompt functionality
|
93 |
-
# The instructor will provide a secret prompt/persona to the tutor
|
94 |
-
with gr.Blocks():
|
95 |
-
# testing purpose, change visible to False at deployment
|
96 |
-
view_secret = gr.Textbox(label="Current secret prompt", value=os.environ.get("SECRET_PROMPT"), visible=False)
|
97 |
-
|
98 |
-
# Prompt instructor to upload the secret file
|
99 |
-
file_input = gr.File(label="Load a .txt or .py file", file_types=['.py', '.txt'], type="file", elem_classes="short-height")
|
100 |
-
|
101 |
-
# Verify prompt content
|
102 |
-
instructor_prompt = gr.Textbox(label="Verify your prompt content", visible=True)
|
103 |
-
file_input.upload(fn=get_instructor_prompt, inputs=file_input, outputs=instructor_prompt)
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
)
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
# one possible way is to recreate the instructor interface in another space,
|
124 |
-
# and load it here to chain with the student interface
|
125 |
-
|
126 |
-
# TODO: Currently, the instructor prompt is handled as text input and stored in the vector store (and in the learning objective),
|
127 |
-
# which means the tutor now is still a question-answering tutor who viewed the prompt as context (but not really acting based on it).
|
128 |
-
# We need to find a way to provide the prompt directly to the model and set its status.
|
129 |
|
|
|
|
|
|
|
|
|
130 |
demo.queue().launch(server_name='0.0.0.0', server_port=7860)
|
|
|
32 |
#initialize tutor (with state)
|
33 |
study_tutor = gr.State(SlightlyDelusionalTutor())
|
34 |
|
35 |
+
# Student chatbot interface
|
36 |
+
gr.Markdown("""
|
37 |
+
## Chat with the Model
|
38 |
+
Description here
|
39 |
+
""")
|
|
|
|
|
|
|
40 |
|
41 |
+
"""
|
42 |
+
API Authentication functionality
|
43 |
+
Instead of ask students to provide key, the key is now provided by the instructor.
|
44 |
+
To permanently set the key, go to Settings -> Variables and secrets -> Secrets,
|
45 |
+
then replace OPENAI_API_KEY value with whatever openai key of the instructor.
|
46 |
+
"""
|
47 |
+
api_input = gr.Textbox(show_label=False, type="password", visible=False, value=os.environ.get("OPENAI_API_KEY"))
|
48 |
|
49 |
+
# The instructor will provide a secret prompt/persona to the tutor
|
50 |
+
instructor_prompt = gr.Textbox(label="Verify your prompt content", value = os.environ.get("SECRET_PROMPT"), visible=False)
|
51 |
+
|
52 |
+
# Placeholders components
|
53 |
+
text_input_none = gr.Textbox(visible=False)
|
54 |
+
file_input_none = gr.File(visible=False)
|
55 |
+
instructor_input_none = gr.TextArea(visible=False)
|
56 |
+
learning_objectives_none = gr.Textbox(visible=False)
|
57 |
|
58 |
+
# Set the secret prompt in this session and embed it to the study tutor
|
59 |
+
prompt_submit_btn = gr.Button("Initialize Tutor")
|
60 |
+
prompt_submit_btn.click(
|
61 |
+
fn=create_reference_store,
|
62 |
+
inputs=[study_tutor, prompt_submit_btn, instructor_prompt, file_input_none, instructor_input_none, api_input, instructor_prompt],
|
63 |
+
outputs=[study_tutor, prompt_submit_btn]
|
64 |
+
)
|
65 |
|
66 |
+
with gr.Row(equal_height=True):
|
67 |
+
with gr.Column(scale=2):
|
68 |
+
chatbot = gr.Chatbot()
|
|
|
|
|
|
|
69 |
with gr.Row():
|
70 |
+
user_chat_input = gr.Textbox(label="User input", scale=9)
|
71 |
+
user_chat_submit = gr.Button("Ask/answer model", scale=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
# First add user's message to the conversation history
|
74 |
+
# Then get reply from the tutor and add that to the conversation history
|
75 |
+
user_chat_submit.click(
|
76 |
+
fn = add_user_message, inputs = [user_chat_input, study_tutor], outputs = [user_chat_input, chatbot, study_tutor], queue=False
|
77 |
+
).then(
|
78 |
+
fn = get_tutor_reply, inputs = [study_tutor], outputs = [user_chat_input, chatbot, study_tutor], queue=True
|
79 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
+
# Testing the chat history storage, can be deleted at deployment
|
82 |
+
with gr.Blocks():
|
83 |
+
test_btn = gr.Button("View your chat history")
|
84 |
+
chat_history = gr.JSON(label = "conversation history")
|
85 |
+
test_btn.click(get_conversation_history, inputs=[study_tutor], outputs=[chat_history, study_tutor])
|
86 |
|
87 |
+
# Download conversation history file
|
88 |
+
with gr.Blocks():
|
89 |
+
gr.Markdown("""
|
90 |
+
## Export Your Chat History
|
91 |
+
Export your chat history as a .json, .txt, or .csv file
|
92 |
+
""")
|
93 |
+
with gr.Row():
|
94 |
+
export_dialogue_button_json = gr.Button("JSON")
|
95 |
+
export_dialogue_button_txt = gr.Button("TXT")
|
96 |
+
export_dialogue_button_csv = gr.Button("CSV")
|
97 |
+
|
98 |
+
file_download = gr.Files(label="Download here", file_types=['.json', '.txt', '.csv'], type="file", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
+
export_dialogue_button_json.click(save_json, study_tutor, file_download, show_progress=True)
|
101 |
+
export_dialogue_button_txt.click(save_txt, study_tutor, file_download, show_progress=True)
|
102 |
+
export_dialogue_button_csv.click(save_csv, study_tutor, file_download, show_progress=True)
|
103 |
+
|
104 |
demo.queue().launch(server_name='0.0.0.0', server_port=7860)
|