brunhild217 commited on
Commit
daf6d51
·
1 Parent(s): 2b5fc5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -34
app.py CHANGED
@@ -3,8 +3,6 @@ import gradio as gr
3
  import pandas as pd
4
  from functools import partial
5
  from ai_classroom_suite.UIBaseComponents import *
6
- from ai_classroom_suite.MediaVectorStores import *
7
- from ai_classroom_suite.PromptInteractionBase import *
8
 
9
  # Testing purpose
10
  class EchoingTutor(SlightlyDelusionalTutor):
@@ -38,33 +36,7 @@ def get_tutor_reply(chat_tutor):
38
 
39
  def get_conversation_history(chat_tutor):
40
  return chat_tutor.conversation_memory, chat_tutor
41
-
42
- def create_prompt_store(chat_tutor, vs_button, text_cp, openai_auth):
43
- text_segs = []
44
- upload_segs = []
45
-
46
- if text_cp.strip():
47
- text_segs = get_document_segments(text_cp, 'text', chunk_size=700, chunk_overlap=100)
48
- [doc.metadata.update({'source':'text box'}) for doc in text_segs];
49
 
50
- # get the full list of everything
51
- all_segs = text_segs + upload_segs
52
- print(all_segs)
53
-
54
- # create the vector store and update tutor
55
- vs_db, vs_retriever = create_local_vector_store(all_segs, search_kwargs={"k": 2})
56
- chat_tutor.vector_store = vs_db
57
- chat_tutor.vs_retriever = vs_retriever
58
-
59
- # create the tutor chain
60
- if not chat_tutor.api_key_valid or not chat_tutor.openai_auth:
61
- chat_tutor = embed_key(openai_auth, chat_tutor)
62
- qa_chain = create_tutor_mdl_chain(kind="retrieval_qa", mdl=chat_tutor.chat_llm, retriever = chat_tutor.vs_retriever, return_source_documents=True)
63
- chat_tutor.tutor_chain = qa_chain
64
-
65
- # return the store
66
- return chat_tutor, gr.update(interactive=True, value='Tutor Initialized!')
67
-
68
 
69
  ### Instructor Interface Helper Functions ###
70
  def get_instructor_prompt(fileobj):
@@ -137,6 +109,7 @@ with gr.Blocks() as demo:
137
  with gr.Tab("Instructor Only"):
138
  # API Authentication functionality
139
  # Instead of ask students to provide key, the key is now provided by the instructor
 
140
  """
141
  To permanently set the key, go to Settings -> Variables and secrets -> Secrets,
142
  then replace OPENAI_API_KEY value with whatever openai key of the instructor.
@@ -148,10 +121,13 @@ with gr.Blocks() as demo:
148
  with gr.Blocks():
149
  # testing purpose, change visible to False at deployment
150
  test_secret = gr.Textbox(label="Current secret prompt", value=os.environ.get("SECRET_PROMPT"), visible=True)
151
-
152
- file_input = gr.File(label="Load a .txt or .py file",
153
- file_types=['.py', '.txt'], type="file",
154
- elem_classes="short-height")
 
 
 
155
 
156
  # Verify prompt content
157
  instructor_prompt = gr.Textbox(label="Verify your prompt content", visible=True)
@@ -162,8 +138,8 @@ with gr.Blocks() as demo:
162
  prompt_submit_btn.click(
163
  fn=embed_prompt, inputs=[instructor_prompt], outputs=[test_secret]
164
  ).then(
165
- fn=create_prompt_store,
166
- inputs=[study_tutor, prompt_submit_btn, instructor_prompt, api_input],
167
  outputs=[study_tutor, prompt_submit_btn]
168
  )
169
  # TODO: may need a way to set the secret prompt permanently in settings/secret
 
3
  import pandas as pd
4
  from functools import partial
5
  from ai_classroom_suite.UIBaseComponents import *
 
 
6
 
7
  # Testing purpose
8
  class EchoingTutor(SlightlyDelusionalTutor):
 
36
 
37
  def get_conversation_history(chat_tutor):
38
  return chat_tutor.conversation_memory, chat_tutor
 
 
 
 
 
 
 
 
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  ### Instructor Interface Helper Functions ###
42
  def get_instructor_prompt(fileobj):
 
109
  with gr.Tab("Instructor Only"):
110
  # API Authentication functionality
111
  # Instead of ask students to provide key, the key is now provided by the instructor
112
+
113
  """
114
  To permanently set the key, go to Settings -> Variables and secrets -> Secrets,
115
  then replace OPENAI_API_KEY value with whatever openai key of the instructor.
 
121
  with gr.Blocks():
122
  # testing purpose, change visible to False at deployment
123
  test_secret = gr.Textbox(label="Current secret prompt", value=os.environ.get("SECRET_PROMPT"), visible=True)
124
+
125
+ text_input = gr.TextArea(visible=False)
126
+ file_input = gr.File(label="Load a .txt or .py file",
127
+ file_types=['.py', '.txt'], type="file",
128
+ elem_classes="short-height")
129
+ instructor_input = gr.TextArea(visible=False)
130
+ learning_objectives = gr.Textbox(visible=False)
131
 
132
  # Verify prompt content
133
  instructor_prompt = gr.Textbox(label="Verify your prompt content", visible=True)
 
138
  prompt_submit_btn.click(
139
  fn=embed_prompt, inputs=[instructor_prompt], outputs=[test_secret]
140
  ).then(
141
+ fn=create_reference_store,
142
+ inputs=[study_tutor, prompt_submit_btn, text_input, file_input, instructor_input, api_input, learning_objectives],
143
  outputs=[study_tutor, prompt_submit_btn]
144
  )
145
  # TODO: may need a way to set the secret prompt permanently in settings/secret