bluenevus commited on
Commit
7946627
·
1 Parent(s): 8ebd7ab

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +52 -23
app.py CHANGED
@@ -53,14 +53,23 @@ def get_right_col_content(selected_type):
53
  children=[html.Div(id="loading-output")]
54
  ))
55
  controls.append(html.Div(id='document-preview', className="border p-3 mb-3"))
56
- controls.append(dbc.Button("Download Document", id="btn-download", color="success", className="mt-3"))
57
- controls.append(dcc.Download(id="download-document"))
 
 
 
 
 
 
 
 
 
 
 
 
58
  controls.append(html.Hr())
59
- if selected_type == "Shred":
60
- controls.append(
61
- dbc.Button("Generate Document", id={'type': 'btn-generate-doc', 'index': selected_type}, color="primary", className="mb-3")
62
- )
63
- elif selected_type != "Shred":
64
  controls.append(html.Div([
65
  html.Label(f"Upload {selected_type} Document"),
66
  dcc.Upload(
@@ -89,18 +98,29 @@ def get_right_col_content(selected_type):
89
  inline=True,
90
  className="mb-2"
91
  ),
92
- dbc.Button("Generate Document", id={'type': 'btn-generate-doc', 'index': selected_type}, color="primary", className="mb-3"),
93
  ], id={'type': 'doc-type-controls', 'index': selected_type}))
94
- controls.append(dcc.Loading(
95
- id="chat-loading",
96
- type="dot",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  children=[
98
- dbc.Input(id="chat-input", type="text", placeholder="Chat with AI to update document...", className="mb-2", style={'whiteSpace':'pre-wrap'}),
99
- dbc.Button("Send", id="btn-send-chat", color="primary", className="mb-3"),
100
- html.Div(id="chat-output")
101
  ]
102
- ))
103
- return dbc.Card(dbc.CardBody(controls))
104
 
105
  app.layout = dbc.Container([
106
  dcc.Store(id='selected-doc-type', data="Shred"),
@@ -130,7 +150,7 @@ app.layout = dbc.Container([
130
  },
131
  multiple=True
132
  ),
133
- html.Div(id='file-list'),
134
  html.Hr(),
135
  html.Div(
136
  id='doc-type-buttons'
@@ -228,10 +248,18 @@ def update_output(list_of_contents, list_of_names, existing_files):
228
  for i, (content, name) in enumerate(zip(list_of_contents, list_of_names)):
229
  file_content = process_document(content, name)
230
  uploaded_files[name] = file_content
231
- new_files.append(html.Div([
232
- html.Button('×', id={'type': 'remove-file', 'index': name}, style={'marginRight': '5px', 'fontSize': '10px'}),
233
- html.Span(name)
234
- ]))
 
 
 
 
 
 
 
 
235
  if existing_files is None:
236
  existing_files = []
237
  elif not isinstance(existing_files, list):
@@ -269,8 +297,9 @@ def remove_file(n_clicks, existing_files):
269
  if existing_files:
270
  for file in existing_files:
271
  try:
272
- file_name = file['props']['children'][1]['props']['children']
273
- if file_name != removed_file:
 
274
  filtered_files.append(file)
275
  except Exception as e:
276
  filtered_files.append(file)
 
53
  children=[html.Div(id="loading-output")]
54
  ))
55
  controls.append(html.Div(id='document-preview', className="border p-3 mb-3"))
56
+ # Generate and Download buttons in a row, Generate left of Download
57
+ controls.append(
58
+ dbc.Row([
59
+ dbc.Col(
60
+ dbc.Button("Generate Document", id={'type': 'btn-generate-doc', 'index': selected_type}, color="primary", className="mb-3 w-100"),
61
+ width=6
62
+ ),
63
+ dbc.Col(
64
+ dbc.Button("Download Document", id="btn-download", color="success", className="mb-3 w-100"),
65
+ width=6
66
+ ),
67
+ dcc.Download(id="download-document")
68
+ ], className="mb-2")
69
+ )
70
  controls.append(html.Hr())
71
+ # Upload and radio only for non-shred
72
+ if selected_type != "Shred":
 
 
 
73
  controls.append(html.Div([
74
  html.Label(f"Upload {selected_type} Document"),
75
  dcc.Upload(
 
98
  inline=True,
99
  className="mb-2"
100
  ),
 
101
  ], id={'type': 'doc-type-controls', 'index': selected_type}))
102
+ # Chatbox below HR
103
+ controls.append(
104
+ dcc.Loading(
105
+ id="chat-loading",
106
+ type="dot",
107
+ children=[
108
+ dbc.Input(id="chat-input", type="text", placeholder="Chat with AI to update document...", className="mb-2", style={'whiteSpace':'pre-wrap'}),
109
+ dbc.Button("Send", id="btn-send-chat", color="primary", className="mb-3"),
110
+ html.Div(id="chat-output")
111
+ ]
112
+ )
113
+ )
114
+ return dbc.Card(dbc.CardBody(controls))
115
+
116
+ def file_list_component():
117
+ # Each file gets a row with a unique id for remove button
118
+ return html.Div(
119
+ id='file-list-container',
120
  children=[
121
+ html.Div(id='file-list')
 
 
122
  ]
123
+ )
 
124
 
125
  app.layout = dbc.Container([
126
  dcc.Store(id='selected-doc-type', data="Shred"),
 
150
  },
151
  multiple=True
152
  ),
153
+ file_list_component(),
154
  html.Hr(),
155
  html.Div(
156
  id='doc-type-buttons'
 
248
  for i, (content, name) in enumerate(zip(list_of_contents, list_of_names)):
249
  file_content = process_document(content, name)
250
  uploaded_files[name] = file_content
251
+ new_files.append(
252
+ dbc.Row([
253
+ dbc.Col(
254
+ html.Button('×', id={'type': 'remove-file', 'index': name}, style={'marginRight': '5px', 'fontSize': '10px'}),
255
+ width=1
256
+ ),
257
+ dbc.Col(
258
+ html.Span(name, style={'wordBreak': 'break-all'}),
259
+ width=11
260
+ )
261
+ ], id={'type': 'file-row', 'index': name}, align="center", className="mb-1")
262
+ )
263
  if existing_files is None:
264
  existing_files = []
265
  elif not isinstance(existing_files, list):
 
297
  if existing_files:
298
  for file in existing_files:
299
  try:
300
+ # file is a dbc.Row, children[1] is dbc.Col with html.Span(name)
301
+ file_id = file['props']['id']
302
+ if file_id['index'] != removed_file:
303
  filtered_files.append(file)
304
  except Exception as e:
305
  filtered_files.append(file)