Spaces:
Build error
Build error
Commit
·
f934fb5
1
Parent(s):
fa132d6
Update app.py
Browse files
app.py
CHANGED
@@ -37,77 +37,54 @@ def get_tutor_reply(user_message, chat_tutor):
|
|
37 |
def get_conversation_history(chat_tutor):
|
38 |
return chat_tutor.conversation_memory, chat_tutor
|
39 |
|
40 |
-
def student_interface():
|
41 |
-
with gr.Blocks() as demo:
|
42 |
-
#initialize tutor (with state)
|
43 |
-
study_tutor = gr.State(EchoingTutor())
|
44 |
-
|
45 |
-
# API Authentication
|
46 |
-
# Instead of ask students to provide key, the key is now directly provided by the instructor
|
47 |
-
embed_key(os.environ.get("OPENAI_API_KEY"), study_tutor)
|
48 |
-
|
49 |
-
# Chatbot interface
|
50 |
-
gr.Markdown("""
|
51 |
-
## Chat with the Model
|
52 |
-
Description here
|
53 |
-
""")
|
54 |
-
|
55 |
-
with gr.Row(equal_height=True):
|
56 |
-
with gr.Column(scale=2):
|
57 |
-
chatbot = gr.Chatbot()
|
58 |
-
with gr.Row():
|
59 |
-
user_chat_input = gr.Textbox(label="User input", scale=9)
|
60 |
-
user_chat_submit = gr.Button("Ask/answer model", scale=1)
|
61 |
-
|
62 |
-
user_chat_submit.click(add_user_message,
|
63 |
-
[user_chat_input, study_tutor],
|
64 |
-
[chatbot, study_tutor], queue=False).then(
|
65 |
-
get_tutor_reply, [user_chat_input, study_tutor], [user_chat_input, chatbot, study_tutor], queue=True)
|
66 |
-
|
67 |
-
# Testing purpose
|
68 |
-
test_btn = gr.Button("View your chat history")
|
69 |
-
chat_history = gr.JSON(label = "conversation history")
|
70 |
-
test_btn.click(get_conversation_history, inputs=[study_tutor], outputs=[chat_history, study_tutor])
|
71 |
-
|
72 |
-
with gr.Blocks():
|
73 |
-
gr.Markdown("""
|
74 |
-
## Export Your Chat History
|
75 |
-
Export your chat history as a .json, .txt, or .csv file
|
76 |
-
""")
|
77 |
-
with gr.Row():
|
78 |
-
export_dialogue_button_json = gr.Button("JSON")
|
79 |
-
export_dialogue_button_txt = gr.Button("TXT")
|
80 |
-
export_dialogue_button_csv = gr.Button("CSV")
|
81 |
-
|
82 |
-
file_download = gr.Files(label="Download here",
|
83 |
-
file_types=['.json', '.txt', '.csv'], type="file", visible=False)
|
84 |
-
|
85 |
-
export_dialogue_button_json.click(save_json, study_tutor, file_download, show_progress=True)
|
86 |
-
export_dialogue_button_txt.click(save_txt, study_tutor, file_download, show_progress=True)
|
87 |
-
export_dialogue_button_csv.click(save_csv, study_tutor, file_download, show_progress=True)
|
88 |
|
89 |
-
|
|
|
|
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
[gr.Textbox("text", label="Output")],
|
102 |
-
lambda role: role,
|
103 |
-
)
|
104 |
|
105 |
-
role = role_selection.launch()
|
106 |
-
|
107 |
-
if role == "Student":
|
108 |
-
student_interface()
|
109 |
-
elif role == "Instructor":
|
110 |
-
instructor_interface()
|
111 |
|
112 |
-
|
113 |
-
main()
|
|
|
37 |
def get_conversation_history(chat_tutor):
|
38 |
return chat_tutor.conversation_memory, chat_tutor
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
with gr.Blocks() as demo:
|
42 |
+
#initialize tutor (with state)
|
43 |
+
study_tutor = gr.State(EchoingTutor())
|
44 |
|
45 |
+
# API Authentication
|
46 |
+
# Instead of ask students to provide key, the key is now directly provided by the instructor
|
47 |
+
embed_key(os.environ.get("OPENAI_API_KEY"), study_tutor)
|
48 |
+
|
49 |
+
# Chatbot interface
|
50 |
+
gr.Markdown("""
|
51 |
+
## Chat with the Model
|
52 |
+
Description here
|
53 |
+
""")
|
54 |
|
55 |
+
with gr.Row(equal_height=True):
|
56 |
+
with gr.Column(scale=2):
|
57 |
+
chatbot = gr.Chatbot()
|
58 |
+
with gr.Row():
|
59 |
+
user_chat_input = gr.Textbox(label="User input", scale=9)
|
60 |
+
user_chat_submit = gr.Button("Ask/answer model", scale=1)
|
61 |
+
|
62 |
+
user_chat_submit.click(add_user_message,
|
63 |
+
[user_chat_input, study_tutor],
|
64 |
+
[chatbot, study_tutor], queue=False).then(
|
65 |
+
get_tutor_reply, [user_chat_input, study_tutor], [user_chat_input, chatbot, study_tutor], queue=True)
|
66 |
|
67 |
+
# Testing purpose
|
68 |
+
test_btn = gr.Button("View your chat history")
|
69 |
+
chat_history = gr.JSON(label = "conversation history")
|
70 |
+
test_btn.click(get_conversation_history, inputs=[study_tutor], outputs=[chat_history, study_tutor])
|
71 |
+
|
72 |
+
with gr.Blocks():
|
73 |
+
gr.Markdown("""
|
74 |
+
## Export Your Chat History
|
75 |
+
Export your chat history as a .json, .txt, or .csv file
|
76 |
+
""")
|
77 |
+
with gr.Row():
|
78 |
+
export_dialogue_button_json = gr.Button("JSON")
|
79 |
+
export_dialogue_button_txt = gr.Button("TXT")
|
80 |
+
export_dialogue_button_csv = gr.Button("CSV")
|
81 |
+
|
82 |
+
file_download = gr.Files(label="Download here",
|
83 |
+
file_types=['.json', '.txt', '.csv'], type="file", visible=False)
|
84 |
|
85 |
+
export_dialogue_button_json.click(save_json, study_tutor, file_download, show_progress=True)
|
86 |
+
export_dialogue_button_txt.click(save_txt, study_tutor, file_download, show_progress=True)
|
87 |
+
export_dialogue_button_csv.click(save_csv, study_tutor, file_download, show_progress=True)
|
|
|
|
|
|
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
+
demo.queue().launch(server_name='0.0.0.0', server_port=7860)
|
|