\n",
" `;\n",
" element.appendChild(external_link);\n",
"\n",
" const iframe = document.createElement('iframe');\n",
" iframe.src = new URL(path, url).toString();\n",
" iframe.height = height;\n",
" iframe.allow = \"autoplay; camera; microphone; clipboard-read; clipboard-write;\"\n",
" iframe.width = width;\n",
" iframe.style.border = 0;\n",
" element.appendChild(iframe);\n",
" })(7863, \"/\", \"100%\", 500, false, window.element)"
]
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"def prompt_select(selection, number, length):\n",
" if selection == \"Random\":\n",
" prompt = f\"Please design a {number} question quiz based on the context provided and the inputted learning objectives (if applicable). The types of questions should be randomized (including multiple choice, short answer, true/false, short answer, etc.). Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide 1 question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect, and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right.\"\n",
" elif selection == \"Fill in the Blank\":\n",
" prompt = f\"Create a {number} question fill in the blank quiz refrencing the context provided. The quiz should reflect the learning objectives (if inputted). The 'blank' part of the question should appear as '________'. The answers should reflect what word(s) should go in the blank an accurate statement. An example is the follow: 'The author of the article is ______.' The question should be a statement. Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect,and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right.\"\n",
" elif selection == \"Short Answer\":\n",
" prompt = f\"Please design a {number} question quiz about which reflects the learning objectives (if inputted). The questions should be short answer. Expect the correct answers to be {length} sentences long. Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide ONE question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect, and then give me additional chances to respond until I get the correct choice. Explain why the correct answer is right.\"\n",
" else:\n",
" prompt = f\"Please design a {number} question {selection.lower()} quiz based on the context provided and the inputted learning objectives (if applicable). Provide one question at a time, and wait for my response before providing me with feedback. Again, while the quiz may ask for multiple questions, you should only provide 1 question in you initial response. Do not include the answer in your response. If I get an answer wrong, provide me with an explanation of why it was incorrect, and then give me additional chances to respond until I get the correct choice. Explain why the correct choice is right.\"\n",
" return prompt\n",
"\n",
"\n",
"# Function to save prompts (premade or custom) and return in the user input box in the chatbot`\n",
"saved_text = \"\"\n",
"def save_text(text):\n",
" global saved_text\n",
" saved_text = text\n",
"\n",
"def return_text():\n",
" # Return the saved text\n",
" return saved_text"
],
"metadata": {
"id": "wF80F1wU80rU"
},
"execution_count": 14,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"### Baseline Functionality V3"
],
"metadata": {
"id": "F5-Ja2evCE4X"
}
},
{
"cell_type": "markdown",
"source": [
"Updated Question Selection and Chatbot Feature"
],
"metadata": {
"id": "rr8YlzcJCKv4"
}
},
{
"cell_type": "code",
"source": [
"with gr.Blocks() as demo:\n",
" gr.Markdown(\"# Oral Exam App\")\n",
" gr.Markdown(\"## OpenAI API key\")\n",
" with gr.Box():\n",
" gr.HTML(\"\"\"Embed your OpenAI API key below; if you haven't created one already, visit\n",
" platform.openai.com/account/api-keys\n",
" to sign up for an account and get your personal API key\"\"\",\n",
" elem_classes=\"textbox_label\")\n",
" input = gr.Textbox(show_label=False, type=\"password\", container=False,\n",
" placeholder=\"●●●●●●●●●●●●●●●●●\")\n",
" input.change(fn=embed_key, inputs=input, outputs=None)\n",
"\n",
" with gr.Blocks():\n",
" #########################\n",
" #########Context#########\n",
" #########################\n",
" with gr.Accordion(\"Context section\"):\n",
" ### Should also allow vector stores\n",
" gr.Markdown(\"## Please upload the context document(s) for Oral exam\")\n",
" context_input = gr.File(label=\"Click to upload context file\",\n",
" file_count=\"multiple\",\n",
" file_types=[\".txt\", \".docx\", \".pdf\"])\n",
" outputs_context=gr.Textbox(label=\"Context\")\n",
" context_input.change(fn=process_file, inputs=context_input, outputs=outputs_context)\n",
" # upload_button = gr.Button(value=\"Show context\")\n",
" # upload_button.click(process_file, context_input, outputs_context)\n",
"\n",
" with gr.Blocks():\n",
" gr.Markdown(\"\"\"\n",
" ## Generate a Premade Prompt\n",
" Select your type and number of desired questions. Click \"Generate Prompt\" to get your premade prompt,\n",
" and then \"Insert Prompt into Chat\" to copy the text into the chat interface below. \\\n",
" You can also copy the prompt using the icon in the upper right corner and paste directly into the input box when interacting with the model.\n",
" \"\"\")\n",
" with gr.Row():\n",
" with gr.Column():\n",
" question_type = gr.Dropdown([\"Multiple Choice\", \"True or False\", \"Short Answer\", \"Fill in the Blank\", \"Random\"], label=\"Question Type\")\n",
" number_of_questions = gr.Textbox(label=\"Enter desired number of questions\")\n",
" sa_desired_length = gr.Dropdown([\"1-2\", \"3-4\", \"5-6\", \"6 or more\"], label = \"For short answer questions only, choose the desired sentence length for answers. The default value is 1-2 sentences.\")\n",
" with gr.Column():\n",
" prompt_button = gr.Button(\"Generate Prompt\")\n",
" premade_prompt_output = gr.Textbox(label=\"Generated prompt (save or copy)\", show_copy_button=True)\n",
" prompt_button.click(prompt_select,\n",
" inputs=[question_type, number_of_questions, sa_desired_length],\n",
" outputs=premade_prompt_output)\n",
" ########################\n",
" ##Question Generation###\n",
" ########################\n",
" with gr.Accordion(\"Question section\"):\n",
" gr.Markdown(\"## Questions\")\n",
" with gr.Row():\n",
" with gr.Column():\n",
" outputs_qa=gr.Textbox(label=\"Generate questions\")\n",
" btn1 = gr.Button(value=\"Generate questions\")\n",
" btn1.click(generate_questions_v2, inputs=[outputs_context, premade_prompt_output], outputs=outputs_qa)\n",
"\n",
" ######################### Need additional work to include these questions when click button #########################\n",
" with gr.Column():\n",
" submit_question=gr.Textbox(label=\"Use existing questions\")\n",
" btn4 = gr.Button(value=\"Use these questions\")\n",
" # btn4.click(use_this_question, inputs=outputs_transcribe, outputs=None)\n",
"\n",
" #########################\n",
" #######Main Audio########\n",
" #########################\n",
" with gr.Accordion(\"Main audio section\"):\n",
" gr.Markdown(\"## Upload your audio file or start recording\")\n",
" with gr.Column():\n",
" ## uploading files seem not working (don't know why)\n",
" with gr.Row():\n",
" file_input = gr.Audio(label=\"Upload Audio\", source=\"upload\", type=\"filepath\")\n",
" record_inputs = gr.Audio(label=\"Record Audio\", source=\"microphone\", type=\"filepath\")\n",
"\n",
" gr.Markdown(\"## Transcribe the audio uploaded or recorded\")\n",
" outputs_transcribe=gr.Textbox(label=\"Transcription\")\n",
"\n",
" file_input.change(fn=transcribe, inputs=file_input, outputs=outputs_transcribe)\n",
" record_inputs.change(fn=transcribe, inputs=record_inputs, outputs=outputs_transcribe)\n",
"\n",
" #########################\n",
" #######Evaluation########\n",
" #########################\n",
" with gr.Accordion(\"Evaluation section\"):\n",
" gr.Markdown(\"## Evaluation\")\n",
" with gr.Tab(\"General evalution\"):\n",
" evalution=gr.Textbox(label=\"AI Evaluation\")\n",
" btn5 = gr.Button(value=\"Evaluate\")\n",
" btn5.click(ai_evaluate_v2, inputs=[outputs_context, outputs_transcribe, outputs_qa], outputs=evalution)\n",
" with gr.Tab(\"Quantitative evalution\"):\n",
" table_output = gr.Dataframe(label = \"Some kind of evaluation metrics?\")\n",
" btn6 = gr.Button(value=\"Evaluate\")\n",
" btn6.click(ai_evaluate_v2, inputs=[outputs_context, outputs_transcribe, outputs_qa], outputs=table_output)\n",
"\n",
"\n",
" # Chatbot (https://gradio.app/creating-a-chatbot/)\n",
" '''\n",
" with gr.Blocks():\n",
" gr.Markdown(\"\"\"\n",
" ## Chat with the Model\n",
" Click \"Display Prompt\" to display the premade or custom prompt that you created earlier. Then, continue chatting with the model.\n",
" \"\"\")\n",
" with gr.Row():\n",
" show_prompt_block = gr.Button(\"Display Prompt\")\n",
" '''\n",
" gr.Markdown(\"## Chat with the Model\")\n",
" with gr.Row(equal_height=True):\n",
" with gr.Column(scale=2):\n",
" chatbot = gr.Chatbot()\n",
" with gr.Row():\n",
" user_chat_input = gr.Textbox(label=\"User input\", scale=9)\n",
" user_chat_input.submit(return_text, inputs=None, outputs=user_chat_input)\n",
" user_chat_submit = gr.Button(\"Ask/answer model\", scale=1)\n",
" #show_prompt_block.click(return_text, inputs=None, outputs=user_chat_input)\n",
"\n",
" # TODO Move the sources so it's displayed to the right of the chat bot,\n",
" # with the sources taking up about 1/3rd of the horizontal space\n",
" # with gr.Box(elem_id=\"sources-container\", scale=1):\n",
" # # TODO: Display document sources in a nicer format?\n",
" # gr.HTML(value=\"
Sources
\")\n",
" # sources_output = []\n",
" # for i in range(num_sources):\n",
" # source_elem = gr.HTML(visible=False)\n",
" # sources_output.append(source_elem)\n",
"\n",
"demo.launch()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 616
},
"id": "Y7-3JFuZ8H5k",
"outputId": "ea99ce65-7b79-4d39-dd88-44785b0d6615"
},
"execution_count": 24,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
"Note: opening Chrome Inspector may crash demo inside Colab notebooks.\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
""
],
"application/javascript": [
"(async (port, path, width, height, cache, element) => {\n",
" if (!google.colab.kernel.accessAllowed && !cache) {\n",
" return;\n",
" }\n",
" element.appendChild(document.createTextNode(''));\n",
" const url = await google.colab.kernel.proxyPort(port, {cache});\n",
"\n",
" const external_link = document.createElement('div');\n",
" external_link.innerHTML = `\n",
"