Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -52,8 +52,7 @@ def get_right_col_content(selected_type):
|
|
52 |
type="dot",
|
53 |
children=[html.Div(id="loading-output")]
|
54 |
))
|
55 |
-
|
56 |
-
# Generate and Download buttons in a row, Generate left of Download
|
57 |
controls.append(
|
58 |
dbc.Row([
|
59 |
dbc.Col(
|
@@ -68,6 +67,7 @@ def get_right_col_content(selected_type):
|
|
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([
|
@@ -99,22 +99,57 @@ def get_right_col_content(selected_type):
|
|
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=[
|
@@ -127,35 +162,7 @@ app.layout = dbc.Container([
|
|
127 |
dbc.Row([
|
128 |
dbc.Col(
|
129 |
dbc.Card(
|
130 |
-
dbc.CardBody(
|
131 |
-
html.H4("Proposal Documents", className="mt-3 mb-4"),
|
132 |
-
html.Div([
|
133 |
-
html.Div(className="blinking-dot", style={'margin':'0 auto','width':'16px','height':'16px'}),
|
134 |
-
], style={'textAlign':'center', 'marginBottom':'10px'}),
|
135 |
-
dcc.Upload(
|
136 |
-
id='upload-document',
|
137 |
-
children=html.Div([
|
138 |
-
'Drag and Drop or ',
|
139 |
-
html.A('Select Files')
|
140 |
-
]),
|
141 |
-
style={
|
142 |
-
'width': '100%',
|
143 |
-
'height': '60px',
|
144 |
-
'lineHeight': '60px',
|
145 |
-
'borderWidth': '1px',
|
146 |
-
'borderStyle': 'dashed',
|
147 |
-
'borderRadius': '5px',
|
148 |
-
'textAlign': 'center',
|
149 |
-
'margin': '10px 0'
|
150 |
-
},
|
151 |
-
multiple=True
|
152 |
-
),
|
153 |
-
file_list_component(),
|
154 |
-
html.Hr(),
|
155 |
-
html.Div(
|
156 |
-
id='doc-type-buttons'
|
157 |
-
)
|
158 |
-
])
|
159 |
),
|
160 |
width=3
|
161 |
),
|
@@ -297,7 +304,6 @@ def remove_file(n_clicks, existing_files):
|
|
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)
|
@@ -346,12 +352,10 @@ def generate_any_doc(n_clicks_list, btn_ids, radio_values, upload_contents, uplo
|
|
346 |
logging.error(f"Error generating document: {str(e)}")
|
347 |
return html.Div(f"Error generating document: {str(e)}"), "Error"
|
348 |
|
349 |
-
# For other doc types, handle radio/upload logic
|
350 |
if shredded_document is None:
|
351 |
logging.info("Shredded document is None. Aborting.")
|
352 |
return html.Div("Please shred a document first."), ""
|
353 |
|
354 |
-
# Defensive: radio_values, upload_contents, upload_filenames may be None or short
|
355 |
source = None
|
356 |
if radio_values and len(radio_values) > idx:
|
357 |
source = radio_values[idx]
|
@@ -436,14 +440,19 @@ def spreadsheet_preview(text, doc_type=None):
|
|
436 |
if doc_type in spreadsheet_types:
|
437 |
try:
|
438 |
df = pd.read_csv(StringIO(text))
|
439 |
-
|
|
|
440 |
except Exception as e:
|
441 |
logging.error(f"Error parsing CSV for preview: {str(e)}")
|
442 |
-
return html.
|
|
|
|
|
|
|
443 |
else:
|
444 |
try:
|
445 |
df = pd.read_csv(StringIO(text))
|
446 |
-
|
|
|
447 |
except Exception:
|
448 |
return html.Pre(text, style={'whiteSpace': 'pre-wrap', 'fontFamily': 'monospace'})
|
449 |
|
|
|
52 |
type="dot",
|
53 |
children=[html.Div(id="loading-output")]
|
54 |
))
|
55 |
+
# Generate and Download buttons at the top
|
|
|
56 |
controls.append(
|
57 |
dbc.Row([
|
58 |
dbc.Col(
|
|
|
67 |
], className="mb-2")
|
68 |
)
|
69 |
controls.append(html.Hr())
|
70 |
+
controls.append(html.Div(id='document-preview', className="border p-3 mb-3"))
|
71 |
# Upload and radio only for non-shred
|
72 |
if selected_type != "Shred":
|
73 |
controls.append(html.Div([
|
|
|
99 |
className="mb-2"
|
100 |
),
|
101 |
], id={'type': 'doc-type-controls', 'index': selected_type}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
return dbc.Card(dbc.CardBody(controls))
|
103 |
|
104 |
+
def get_left_col_content():
|
105 |
+
# Chat card under doc-type buttons
|
106 |
+
chat_card = dbc.Card(
|
107 |
+
dbc.CardBody([
|
108 |
+
html.H5("AI Chat", className="mb-2"),
|
109 |
+
dcc.Loading(
|
110 |
+
id="chat-loading",
|
111 |
+
type="dot",
|
112 |
+
children=[
|
113 |
+
dbc.Input(id="chat-input", type="text", placeholder="Chat with AI to update document...", className="mb-2", style={'whiteSpace':'pre-wrap'}),
|
114 |
+
dbc.Button("Send", id="btn-send-chat", color="primary", className="mb-3"),
|
115 |
+
html.Div(id="chat-output")
|
116 |
+
]
|
117 |
+
)
|
118 |
+
]),
|
119 |
+
className="mt-4"
|
120 |
+
)
|
121 |
+
return [
|
122 |
+
html.H4("Proposal Documents", className="mt-3 mb-4"),
|
123 |
+
html.Div([
|
124 |
+
html.Div(className="blinking-dot", style={'margin':'0 auto','width':'16px','height':'16px'}),
|
125 |
+
], style={'textAlign':'center', 'marginBottom':'10px'}),
|
126 |
+
dcc.Upload(
|
127 |
+
id='upload-document',
|
128 |
+
children=html.Div([
|
129 |
+
'Drag and Drop or ',
|
130 |
+
html.A('Select Files')
|
131 |
+
]),
|
132 |
+
style={
|
133 |
+
'width': '100%',
|
134 |
+
'height': '60px',
|
135 |
+
'lineHeight': '60px',
|
136 |
+
'borderWidth': '1px',
|
137 |
+
'borderStyle': 'dashed',
|
138 |
+
'borderRadius': '5px',
|
139 |
+
'textAlign': 'center',
|
140 |
+
'margin': '10px 0'
|
141 |
+
},
|
142 |
+
multiple=True
|
143 |
+
),
|
144 |
+
file_list_component(),
|
145 |
+
html.Hr(),
|
146 |
+
html.Div(
|
147 |
+
id='doc-type-buttons'
|
148 |
+
),
|
149 |
+
chat_card
|
150 |
+
]
|
151 |
+
|
152 |
def file_list_component():
|
|
|
153 |
return html.Div(
|
154 |
id='file-list-container',
|
155 |
children=[
|
|
|
162 |
dbc.Row([
|
163 |
dbc.Col(
|
164 |
dbc.Card(
|
165 |
+
dbc.CardBody(get_left_col_content())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
),
|
167 |
width=3
|
168 |
),
|
|
|
304 |
if existing_files:
|
305 |
for file in existing_files:
|
306 |
try:
|
|
|
307 |
file_id = file['props']['id']
|
308 |
if file_id['index'] != removed_file:
|
309 |
filtered_files.append(file)
|
|
|
352 |
logging.error(f"Error generating document: {str(e)}")
|
353 |
return html.Div(f"Error generating document: {str(e)}"), "Error"
|
354 |
|
|
|
355 |
if shredded_document is None:
|
356 |
logging.info("Shredded document is None. Aborting.")
|
357 |
return html.Div("Please shred a document first."), ""
|
358 |
|
|
|
359 |
source = None
|
360 |
if radio_values and len(radio_values) > idx:
|
361 |
source = radio_values[idx]
|
|
|
440 |
if doc_type in spreadsheet_types:
|
441 |
try:
|
442 |
df = pd.read_csv(StringIO(text))
|
443 |
+
table = dbc.Table.from_dataframe(df, striped=True, bordered=True, hover=True, size="sm")
|
444 |
+
return html.Div(table)
|
445 |
except Exception as e:
|
446 |
logging.error(f"Error parsing CSV for preview: {str(e)}")
|
447 |
+
return html.Div([
|
448 |
+
html.Div("Unable to display spreadsheet preview. Raw output:", style={'fontWeight': 'bold'}),
|
449 |
+
html.Pre(text, style={'whiteSpace': 'pre-wrap', 'fontFamily': 'monospace'})
|
450 |
+
])
|
451 |
else:
|
452 |
try:
|
453 |
df = pd.read_csv(StringIO(text))
|
454 |
+
table = dbc.Table.from_dataframe(df, striped=True, bordered=True, hover=True, size="sm")
|
455 |
+
return html.Div(table)
|
456 |
except Exception:
|
457 |
return html.Pre(text, style={'whiteSpace': 'pre-wrap', 'fontFamily': 'monospace'})
|
458 |
|