bluenevus commited on
Commit
7038ced
·
1 Parent(s): d1d0218

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +100 -76
app.py CHANGED
@@ -124,6 +124,7 @@ def get_right_col_content(selected_type):
124
  )
125
 
126
  app.layout = dbc.Container([
 
127
  dbc.Row([
128
  dbc.Col(
129
  dbc.Card(
@@ -152,15 +153,9 @@ app.layout = dbc.Container([
152
  ),
153
  html.Div(id='file-list'),
154
  html.Hr(),
155
- html.Div([
156
- dbc.Button(
157
- doc_type,
158
- id={'type': 'btn-doc-type', 'index': doc_type},
159
- color="link",
160
- className="mb-2 w-100 text-left custom-button",
161
- style={'overflow': 'hidden', 'text-overflow': 'ellipsis', 'white-space': 'nowrap'}
162
- ) for doc_type in document_types.keys()
163
- ])
164
  ])
165
  ),
166
  width=3
@@ -172,6 +167,52 @@ app.layout = dbc.Container([
172
  ])
173
  ], fluid=True)
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  def process_document(contents, filename):
176
  content_type, content_string = contents.split(',')
177
  decoded = base64.b64decode(content_string)
@@ -235,73 +276,6 @@ def remove_file(n_clicks, existing_files):
235
  logging.info(f"Removed file: {removed_file}")
236
  return [file for file in existing_files if file['props']['children'][1]['props']['children'] != removed_file]
237
 
238
- @app.callback(
239
- Output('right-col-content', 'children'),
240
- [Input({'type': 'btn-doc-type', 'index': ALL}, 'n_clicks')],
241
- [State({'type': 'btn-doc-type', 'index': ALL}, 'id')]
242
- )
243
- def update_right_col(n_clicks_list, btn_ids):
244
- triggered = callback_context.triggered
245
- if not triggered or all(x is None for x in n_clicks_list):
246
- selected_type = "Shred"
247
- else:
248
- idx = [i for i, x in enumerate(n_clicks_list) if x]
249
- if idx:
250
- selected_type = btn_ids[idx[-1]]['index']
251
- else:
252
- selected_type = "Shred"
253
- return get_right_col_content(selected_type)
254
-
255
- def generate_document(document_type, file_contents):
256
- prompt = f"""Generate a {document_type} based on the following project artifacts:
257
- {' '.join(file_contents)}
258
- Instructions:
259
- 1. Create the {document_type} as a detailed document.
260
- 2. Use proper formatting and structure.
261
- 3. Include all necessary sections and details.
262
- 4. Start the output immediately with the document content.
263
- 5. IMPORTANT: If the document type is Pink, Red, Gold and not
264
- Pink Review, Red Review, Gold Review, or spreadsheet, loe or virtual board
265
- then your goal is to be compliant and compelling based on the
266
- requrements, write in paragraph in active voice as
267
- MicroHealth, limit bullets, answer the
268
- requirement with what MicroHealth will do
269
- to satisfy the requirement, the technical
270
- approach with innovation for efficiency,
271
- productivity, quality and measurable
272
- outcomes, the industry standard that
273
- methodology is based on if applicable,
274
- detail the workflow or steps to accomplish
275
- the requirement with labor categories that
276
- will do those tasks in that workflow,
277
- reference reputable research like gartner,
278
- forrester, IDC, Deloitte, Accenture etc
279
- with measures of success and substantiation
280
- of MicroHealth's approach. Never use soft words
281
- like maybe, could be, should, possible be definitive in your language and confident.
282
- 6. you must also take into account section L&M of the document which is the evaluation criteria
283
- to be sure we address them.
284
- Now, generate the {document_type}:
285
- """
286
-
287
- logging.info(f"Generating document for type: {document_type}")
288
- try:
289
- response = openai.ChatCompletion.create(
290
- model="gpt-4-1106-preview",
291
- messages=[
292
- {"role": "system", "content": "You are a helpful, expert government proposal writer."},
293
- {"role": "user", "content": prompt}
294
- ],
295
- max_tokens=4096,
296
- temperature=0.25,
297
- )
298
- generated_text = response['choices'][0]['message']['content']
299
- logging.info("Document generated successfully.")
300
- return generated_text
301
- except Exception as e:
302
- logging.error(f"Error generating document: {str(e)}")
303
- raise
304
-
305
  @app.callback(
306
  Output('document-preview', 'children'),
307
  Output('loading-output', 'children'),
@@ -405,6 +379,56 @@ def generate_other_doc(n_clicks_list, btn_ids, radio_values, upload_contents, up
405
  logging.error(f"Error generating document: {str(e)}")
406
  return html.Div(f"Error generating document: {str(e)}"), "Error"
407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
  @app.callback(
409
  Output('chat-output', 'children'),
410
  Output('document-preview', 'children', allow_duplicate=True),
 
124
  )
125
 
126
  app.layout = dbc.Container([
127
+ dcc.Store(id='selected-doc-type', data="Shred"),
128
  dbc.Row([
129
  dbc.Col(
130
  dbc.Card(
 
153
  ),
154
  html.Div(id='file-list'),
155
  html.Hr(),
156
+ html.Div(
157
+ id='doc-type-buttons'
158
+ )
 
 
 
 
 
 
159
  ])
160
  ),
161
  width=3
 
167
  ])
168
  ], fluid=True)
169
 
170
+ @app.callback(
171
+ Output('doc-type-buttons', 'children'),
172
+ Input('selected-doc-type', 'data')
173
+ )
174
+ def render_doc_type_buttons(selected_type):
175
+ buttons = []
176
+ for doc_type in document_types.keys():
177
+ btn_style = {'overflow': 'hidden', 'text-overflow': 'ellipsis', 'white-space': 'nowrap'}
178
+ btn_class = "mb-2 w-100 text-left custom-button"
179
+ if doc_type == selected_type:
180
+ btn_class += " active-doc-type"
181
+ buttons.append(
182
+ dbc.Button(
183
+ doc_type,
184
+ id={'type': 'btn-doc-type', 'index': doc_type},
185
+ color="link",
186
+ className=btn_class,
187
+ style=btn_style
188
+ )
189
+ )
190
+ return buttons
191
+
192
+ @app.callback(
193
+ Output('selected-doc-type', 'data'),
194
+ [Input({'type': 'btn-doc-type', 'index': ALL}, 'n_clicks')],
195
+ [State({'type': 'btn-doc-type', 'index': ALL}, 'id')],
196
+ prevent_initial_call=True
197
+ )
198
+ def update_selected_doc_type(n_clicks_list, btn_ids):
199
+ triggered = callback_context.triggered
200
+ if not triggered or all(x is None for x in n_clicks_list):
201
+ raise dash.exceptions.PreventUpdate
202
+ idx = [i for i, x in enumerate(n_clicks_list) if x]
203
+ if idx:
204
+ selected_type = btn_ids[idx[-1]]['index']
205
+ else:
206
+ selected_type = "Shred"
207
+ return selected_type
208
+
209
+ @app.callback(
210
+ Output('right-col-content', 'children'),
211
+ Input('selected-doc-type', 'data')
212
+ )
213
+ def update_right_col(selected_type):
214
+ return get_right_col_content(selected_type)
215
+
216
  def process_document(contents, filename):
217
  content_type, content_string = contents.split(',')
218
  decoded = base64.b64decode(content_string)
 
276
  logging.info(f"Removed file: {removed_file}")
277
  return [file for file in existing_files if file['props']['children'][1]['props']['children'] != removed_file]
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  @app.callback(
280
  Output('document-preview', 'children'),
281
  Output('loading-output', 'children'),
 
379
  logging.error(f"Error generating document: {str(e)}")
380
  return html.Div(f"Error generating document: {str(e)}"), "Error"
381
 
382
+ def generate_document(document_type, file_contents):
383
+ prompt = f"""Generate a {document_type} based on the following project artifacts:
384
+ {' '.join(file_contents)}
385
+ Instructions:
386
+ 1. Create the {document_type} as a detailed document.
387
+ 2. Use proper formatting and structure.
388
+ 3. Include all necessary sections and details.
389
+ 4. Start the output immediately with the document content.
390
+ 5. IMPORTANT: If the document type is Pink, Red, Gold and not
391
+ Pink Review, Red Review, Gold Review, or spreadsheet, loe or virtual board
392
+ then your goal is to be compliant and compelling based on the
393
+ requrements, write in paragraph in active voice as
394
+ MicroHealth, limit bullets, answer the
395
+ requirement with what MicroHealth will do
396
+ to satisfy the requirement, the technical
397
+ approach with innovation for efficiency,
398
+ productivity, quality and measurable
399
+ outcomes, the industry standard that
400
+ methodology is based on if applicable,
401
+ detail the workflow or steps to accomplish
402
+ the requirement with labor categories that
403
+ will do those tasks in that workflow,
404
+ reference reputable research like gartner,
405
+ forrester, IDC, Deloitte, Accenture etc
406
+ with measures of success and substantiation
407
+ of MicroHealth's approach. Never use soft words
408
+ like maybe, could be, should, possible be definitive in your language and confident.
409
+ 6. you must also take into account section L&M of the document which is the evaluation criteria
410
+ to be sure we address them.
411
+ Now, generate the {document_type}:
412
+ """
413
+
414
+ logging.info(f"Generating document for type: {document_type}")
415
+ try:
416
+ response = openai.ChatCompletion.create(
417
+ model="gpt-4-1106-preview",
418
+ messages=[
419
+ {"role": "system", "content": "You are a helpful, expert government proposal writer."},
420
+ {"role": "user", "content": prompt}
421
+ ],
422
+ max_tokens=4096,
423
+ temperature=0.25,
424
+ )
425
+ generated_text = response['choices'][0]['message']['content']
426
+ logging.info("Document generated successfully.")
427
+ return generated_text
428
+ except Exception as e:
429
+ logging.error(f"Error generating document: {str(e)}")
430
+ raise
431
+
432
  @app.callback(
433
  Output('chat-output', 'children'),
434
  Output('document-preview', 'children', allow_duplicate=True),