{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "import pandas as pd\n", "from transformers import TapasTokenizer, TapasForQuestionAnswering\n", "from transformers import AutoTokenizer, AutoModelForTableQuestionAnswering\n", "from transformers import pipeline\n", "import PIL\n", "\n", "# read the module_guide_tableQA\\0915NC_Studienplaetze.jpg as pil image\n", "pil_image = PIL.Image.open(\"0915NC_Studienplaetze.jpg\")\n", "# make that image a bit less high\n", "pil_image = pil_image.resize((int(pil_image.width * 0.5), int(pil_image.height * 0.5)))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def get_answer(\n", " dropdown,\n", " question,\n", " view_as_table=False,\n", " model=\"google/tapas-finetuned-wtq\",\n", " #progress=gr.Progress(),\n", "):\n", " #progress(0, desc=\"Looking for answer in module guide...\")\n", " df = pd.DataFrame()\n", " if dropdown == \"Master Information Systems\":\n", " df = pd.read_excel(\n", " r\"03_extracted_final_modules\\MS_IS_all_modules_orginal_15_rows_cleaned.xlsx\"\n", " )\n", " elif dropdown == \"Bachelor Information Systems\":\n", " df = pd.read_excel(r\"03_extracted_final_modules\\BA_IS_all_modules_15.xlsx\")\n", " elif dropdown == \"Bachelor Management\":\n", " df = pd.read_excel(r\"03_extracted_final_modules\\BA_MM_all_modules_15.xlsx\")\n", " df = df.astype(str)\n", " print(question)\n", " question = str(question)\n", " print(df.shape)\n", " question = [question]\n", "\n", " if model == \"google/tapas-finetuned-wtq\":\n", " tqa = pipeline(\n", " task=\"table-question-answering\", model=\"google/tapas-base-finetuned-wtq\"\n", " )\n", " elif model == \"google/tapas-large-finetuned-wtq\":\n", " tqa = pipeline(\n", " task=\"table-question-answering\", model=\"google/tapas-large-finetuned-wtq\"\n", " )\n", "\n", " results = tqa(table=df, query=question)\n", " print(results)\n", " cells_input = results[\"cells\"]\n", " cells_input = str(cells_input)\n", " cells_input = cells_input.replace(\"[\", \"\")\n", " cells_input = cells_input.replace(\"]\", \"\")\n", " cells_input = cells_input.replace(\"'\", \"\")\n", "\n", " print(cells_input)\n", " print(results)\n", " html_string_short = f\"

Short Answer:

{cells_input}

\"\n", " row_numbers = [coord[0] for coord in results[\"coordinates\"]]\n", " df_short = df.iloc[row_numbers]\n", " df_short = df_short.dropna(axis=1, how=\"all\")\n", " df_short = df_short.loc[:, (df_short != \"--\").any(axis=0)]\n", " html_table = (\n", " f\"

Complete Module(s):

{df_short.to_html(index=False)}

\"\n", " )\n", "\n", " # check if there are more than 1 rows in df_short\n", " html_string = \"\"\n", " if df_short.shape[0] > 1 or view_as_table == True:\n", " html_string = html_table\n", " elif df_short.shape[0] == 1:\n", " html_string = \"\"\"\n", " \n", " \n", " \n", " \n", "
\n", "

Detailed Module Information

\n", "\n", "
\n", "

Module title:

\n", "

Project Seminar

\n", "
\n", "
\n", "

Abbreviation:

\n", "

12-PS-192-m01

\n", "
\n", "
\n", "

Module coordinator:

\n", "

Faculty of Business Management and Economics

\n", "
\n", "
\n", "

Module offered by:

\n", "

Holder of the Chair of Business Management and Business

\n", "
\n", "
\n", "

ETCS:

\n", "

15

\n", "
\n", "
\n", "

Method of grading:

\n", "

numerical grade

\n", "
\n", "
\n", "

Duration:

\n", "

1 semester

\n", "
\n", "
\n", "

Module level:

\n", "

graduate

\n", "
\n", "
\n", "

Contents:

\n", "

In small project teams of 4 to 10 members, students will spend several months actively working on a specific and realistic problem with practical relevance. They will progress through several project stages including as-is analysis, to-be conception and implementation of an IS solution. The project teams will be required to work independently and will only receive advice and minor support from research assistants.

\n", "
\n", "
\n", "

Intended learning outcomes:

\n", " \n", "
\n", "
\n", "

Courses:

\n", "

Project: preparing a conceptual design (approx. 150 hours), designing and implementing an approach to solution (approx. 300 hours) as well as presentation (approx. 20 minutes), weighted 1:2:1

\n", "

Language of assessment: German, English

\n", "

Creditable for bonus

\n", "
\n", "
\n", "

Workload:

\n", "

450 hours

\n", "
\n", " \n", " \"\"\"\n", " else:\n", " html_string = \"\"\n", "\n", " return html_string_short, html_string\n", "\n", "\n", "def change_html_link(dropdown_item):\n", " html_link = \"\"\n", " if dropdown_item == \"Master Information Systems\":\n", " html_link = f'

View complete pdf here: {dropdown_item}

Ask whatever you want to know about the module guide here. You can ask formality-based and content-based questions.

'\n", " elif dropdown_item == \"Bachelor Information Systems\":\n", " html_link = f'View complete pdf here: {dropdown_item}

Ask whatever you want to know about the module guide here. You can ask formality-based and content-based questions.

'\n", " elif dropdown_item == \"Bachelor Management\":\n", " html_link = f'View complete pdf here: {dropdown_item}

Ask whatever you want to know about the module guide here. You can ask formality-based and content-based questions.

'\n", "\n", " return html_link" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7867\n", "Running on public URL: https://a7a23badcaa31f041e.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "with gr.Blocks() as demo: \n", " gr.HTML(\n", " \"\"\"\n", "
\n", " \"Module\n", "
\n", " \"\"\"\n", " )\n", "\n", " gr.HTML(\n", " \"

Your Module Guide Assistant

\"\n", " )\n", " table = gr.Dropdown(\n", " [\n", " \"Master Information Systems\",\n", " \"Bachelor Information Systems\",\n", " \"Bachelor Management\",\n", " ],\n", " label=\"Select Module Guide\",\n", " value=\"Master Information Systems\",\n", " )\n", " html_link = gr.HTML(\n", " \"\"\"\n", "

View complete PDF here: Master Information Systems

\n", "

Ask whatever you want to know about the module guide here. You can ask formality-based and content-based questions.

\n", " \"\"\"\n", " )\n", "\n", " table.change(change_html_link, table, html_link)\n", " question = gr.Textbox(\n", " label=\"Question\", value=\"How many ECTS credits does the project seminar have?\"\n", " )\n", " with gr.Accordion(\"Advanced Options\", open=False):\n", " with gr.Group():\n", " model_selction = gr.Dropdown(\n", " [\n", " \"google/tapas-finetuned-wtq\",\n", " \"google/tapas-large-finetuned-wtq\",\n", " ],\n", " label=\"Select Model\",\n", " value=\"google/tapas-finetuned-wtq\",\n", " )\n", " view_as_table_or_text = gr.Checkbox(\n", " label=\"View detailed information as table\", value=False\n", " )\n", "\n", " ask_btn = gr.Button(\"Ask The Assistant\")\n", " gr.HTML(\"
\")\n", " inputs = [table, question, view_as_table_or_text, model_selction]\n", " output_question = gr.HTML(label=\"Answer\")\n", " outout_full_module = gr.HTML(label=\"Detailed Description\")\n", " outputs = [output_question, outout_full_module]\n", " ask_btn.click(fn=get_answer, inputs=inputs, outputs=outputs, api_name=\"greet\")\n", "\n", "demo.launch(debug=True, share=True)" ] } ], "metadata": { "kernelspec": { "display_name": "enterpriseai2", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.16" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }