-
Notifications
You must be signed in to change notification settings - Fork 11
initial gpt dashboard plus backend to go with it #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
| } | ||
|
|
||
| .side-panel { | ||
| overflow: hidden; | ||
| transition: all 0.3s ease-in-out; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [metadata] | ||
| name = Writing Observer Automated Essay Feedback | ||
| description = Dashboard for interfacing a classroom of essays with automated feedback | ||
| url = https://github.com/ETS-Next-Gen/writing_observer | ||
| version = 0.1 | ||
|
|
||
| [options] | ||
| packages = wo_bulk_essay_analysis | ||
| include_package_data = true | ||
|
|
||
| [options.entry_points] | ||
| lo_modules = | ||
| wo_bulk_essay_analysis = wo_bulk_essay_analysis.module | ||
|
|
||
| [options.package_data] | ||
| wo_bulk_essay_analysis = dashboard/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ''' | ||
| Rather minimalistic install script. To install, run `python | ||
| setup.py develop` or just install via requirements.txt | ||
| ''' | ||
|
|
||
| from setuptools import setup, find_packages | ||
|
|
||
| setup( | ||
| name="wo_bulk_essay_analysis" | ||
| ) |
142 changes: 142 additions & 0 deletions
142
modules/wo_bulk_essay_analysis/wo_bulk_essay_analysis/assets/scripts.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /** | ||
| * General scripts used for the bulk essay analysis dashboard | ||
| */ | ||
|
|
||
| if (!window.dash_clientside) { | ||
| window.dash_clientside = {} | ||
| } | ||
|
|
||
| const createStudentCard = function (student) { | ||
| const header = { | ||
| namespace: 'dash_bootstrap_components', | ||
| type: 'CardHeader', | ||
| props: { children: student.profile.name.full_name } | ||
| } | ||
| const studentText = { | ||
| namespace: 'lo_dash_react_components', | ||
| type: 'WOAnnotatedText', | ||
| props: { text: student.text, breakpoints: [] } | ||
| } | ||
| const feedback = { | ||
| namespace: 'dash_html_components', | ||
| type: 'Div', | ||
| props: { | ||
| children: student?.feedback ? student.feedback : '', | ||
| className: student?.feedback ? 'border-start p-1 overflow-auto' : '', | ||
| style: { whiteSpace: 'pre-line' } | ||
| } | ||
| } | ||
| const body = { | ||
| namespace: 'lo_dash_react_components', | ||
| type: 'LOPanelLayout', | ||
| props: { | ||
| children: studentText, | ||
| panels: [{ children: feedback, id: 'feedback-text', width: '40%' }], | ||
| shown: feedback.props.children.length > 0 ? ['feedback-text'] : [], | ||
| className: 'overflow-auto p-1' | ||
| } | ||
| } | ||
| const card = { | ||
| namespace: 'dash_bootstrap_components', | ||
| type: 'Card', | ||
| props: { | ||
| children: [header, body], | ||
| style: { maxHeight: '300px' } | ||
| } | ||
| } | ||
| return { | ||
| namespace: 'dash_bootstrap_components', | ||
| type: 'Col', | ||
| props: { | ||
| children: card, | ||
| id: student.user_id, | ||
| width: 4 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const createChatCard = function (chat, user) { | ||
| const teacher = (user === 'teacher') | ||
| const card = { | ||
| namespace: 'dash_bootstrap_components', | ||
| type: 'Card', | ||
| props: { children: chat, body: true, color: teacher ? '#6cc3d540' : '#fff' } | ||
| } | ||
| return { | ||
| namespace: 'dash_bootstrap_components', | ||
| type: 'Col', | ||
| props: { | ||
| children: card, | ||
| align: teacher ? 'end' : 'start', | ||
| width: 9 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| window.dash_clientside.bulk_essay_feedback = { | ||
| send_to_loconnection: async function (state, hash, clicks, query) { | ||
| if (state === undefined) { | ||
| return window.dash_clientside.no_update | ||
| } | ||
| if (state.readyState === 1) { | ||
| if (hash.length === 0) { return window.dash_clientside.no_update } | ||
| const decoded = decode_string_dict(hash.slice(1)) | ||
| if (!decoded.course_id) { return window.dash_clientside.no_update } | ||
|
|
||
| decoded.gpt_prompt = '' | ||
| decoded.message_id = '' | ||
|
|
||
| const trig = window.dash_clientside.callback_context.triggered[0] | ||
| if (trig.prop_id.includes('bulk-essay-analysis-submit-btn')) { | ||
| decoded.gpt_prompt = query | ||
| } | ||
|
|
||
| const message = { | ||
| wo: { | ||
| execution_dag: 'writing_observer', | ||
| target_exports: ['gpt_bulk'], | ||
| kwargs: decoded | ||
| } | ||
| } | ||
| return JSON.stringify(message) | ||
| } | ||
| return window.dash_clientside.no_update | ||
| }, | ||
|
|
||
| update_ui_upon_query_submission: async function (clicks, text, children) { | ||
| if (clicks > 0) { | ||
| const loading = { | ||
| namespace: 'dash_bootstrap_components', | ||
| type: 'Col', | ||
| props: { | ||
| children: { | ||
| namespace: 'dash_bootstrap_components', | ||
| type: 'Spinner', | ||
| props: { color: 'primary' } | ||
| }, | ||
| align: 'start', | ||
| width: 8, | ||
| id: 'loading' | ||
| } | ||
| } | ||
| const newChildren = [loading, createChatCard(text, 'teacher')].concat(children) | ||
| return ['', newChildren] | ||
| } | ||
| }, | ||
|
|
||
| update_student_grid: function (message) { | ||
| const cards = message.map((x) => { | ||
| return createStudentCard(x) | ||
| }) | ||
| return cards | ||
| }, | ||
|
|
||
| add_response_to_chat: function (message, children) { | ||
| const chatCard = createChatCard('Your feedback will appear next to each student card.', 'gpt') | ||
| const index = children.findIndex(item => item.props.id === 'loading') | ||
| if (index > -1) { | ||
| children[index] = chatCard | ||
| } | ||
| return children | ||
| } | ||
| } |
118 changes: 118 additions & 0 deletions
118
modules/wo_bulk_essay_analysis/wo_bulk_essay_analysis/dashboard/layout.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| ''' | ||
| Define layout for dashboard that allows teachers to interface | ||
| student essays with LLMs. | ||
| ''' | ||
| import dash_bootstrap_components as dbc | ||
| import lo_dash_react_components as lodrc | ||
|
|
||
| from dash import html, dcc, callback, Patch, clientside_callback, ClientsideFunction, Output, Input, State | ||
|
|
||
| prefix = 'bulk-essay-analysis' | ||
| websocket = f'{prefix}-websocket' | ||
| ws_store = f'{prefix}-ws-store' | ||
|
|
||
| query_input = f'{prefix}-query-input' | ||
| submit = f'{prefix}-submit-btn' | ||
| chat = f'{prefix}-chat-panel' | ||
| grid = f'{prefix}-essay-grid' | ||
|
|
||
| welcome_message = ['Hello, welcome to the bulk essay analysis.', 'Provide a prompt and we will pass it along with each text into ChatGPT.'] | ||
|
|
||
|
|
||
| def layout(): | ||
| ''' | ||
| Generic layout function to create dashboard | ||
| ''' | ||
| main = html.Div([ | ||
| html.H2('Bulk Essay Analysis'), | ||
| dbc.Row(id=grid, class_name='g-2') | ||
| ], className='vh-100', style={'overflowY': 'auto', 'overflowX': 'hidden'}) | ||
| starting_message = dbc.Col( | ||
| dbc.Card( | ||
| [html.P(message) for message in welcome_message], | ||
| body=True, | ||
| color='#fff' | ||
| ), | ||
| width=9, | ||
| align='start' | ||
| ) | ||
| chat_panel = dbc.Row([ | ||
| dbc.Col( | ||
| dbc.Row([starting_message], id=chat, class_name='h-100 flex-column-reverse flex-nowrap overflow-auto g-1'), | ||
| class_name='flex-grow-1 overflow-auto', | ||
| ), | ||
| dbc.Col( | ||
| dbc.InputGroup([ | ||
| dbc.Textarea(id=query_input, placeholder='Type request here...', autofocus=True, value=''), | ||
| dbc.Button('Submit', id=submit, n_clicks=0, disabled=True), | ||
| ], class_name='p-1'), | ||
| width=12, | ||
| align='end' | ||
| ), | ||
| ], class_name='vh-100 flex-column') | ||
| cont = dbc.Container([ | ||
| lodrc.LOPanelLayout( | ||
| main, | ||
| panels=[{'children': chat_panel, 'width': '25%', 'id': 'chat'}], | ||
| shown=['chat'] | ||
| ), | ||
| lodrc.LOConnection(id=websocket), | ||
| dcc.Store(id=ws_store, data={}) | ||
| ], fluid=True) | ||
| return dcc.Loading(cont) | ||
|
|
||
|
|
||
| # send request to LOConnection | ||
| clientside_callback( | ||
| ClientsideFunction(namespace='bulk_essay_feedback', function_name='send_to_loconnection'), | ||
| Output(websocket, 'send'), | ||
| Input(websocket, 'state'), # used for initial setup | ||
| Input('_pages_location', 'hash'), | ||
| Input(submit, 'n_clicks'), | ||
| State(query_input, 'value'), | ||
| ) | ||
|
|
||
| clientside_callback( | ||
| '''function (value) { | ||
| if (value.length === 0) { return true } | ||
| return false | ||
| } | ||
| ''', | ||
| Output(submit, 'disabled'), | ||
| Input(query_input, 'value') | ||
| ) | ||
|
|
||
| clientside_callback( | ||
| ClientsideFunction(namespace='bulk_essay_feedback', function_name='update_ui_upon_query_submission'), | ||
| Output(query_input, 'value'), | ||
| Output(chat, 'children'), | ||
| Input(submit, 'n_clicks'), | ||
| State(query_input, 'value'), | ||
| State(chat, 'children') | ||
| ) | ||
|
|
||
| # store message from LOConnection in storage for later use | ||
| clientside_callback( | ||
| ''' | ||
| function(message) { | ||
| const data = JSON.parse(message.data).wo.gpt_bulk | ||
| return data | ||
| } | ||
| ''', | ||
| Output(ws_store, 'data'), | ||
| Input(websocket, 'message') | ||
| ) | ||
|
|
||
| clientside_callback( | ||
| ClientsideFunction(namespace='bulk_essay_feedback', function_name='update_student_grid'), | ||
| Output(grid, 'children'), | ||
| Input(ws_store, 'data') | ||
| ) | ||
|
|
||
| clientside_callback( | ||
| ClientsideFunction(namespace='bulk_essay_feedback', function_name='add_response_to_chat'), | ||
| Output(chat, 'children', allow_duplicate=True), | ||
| Input(ws_store, 'data'), | ||
| State(chat, 'children'), | ||
| prevent_initial_call=True | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the - at the bottom might indicate a missing new line at the end of the file.