Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from docx import Document
|
|
10 |
from io import BytesIO
|
11 |
import dash
|
12 |
import dash_bootstrap_components as dbc
|
13 |
-
from dash import html, dcc, Input, Output, State, ctx, dash_table
|
14 |
import google.generativeai as genai
|
15 |
from docx import Document
|
16 |
from docx.shared import Pt
|
@@ -631,21 +631,28 @@ def download_g_review(n_clicks, g_review_output):
|
|
631 |
@app.callback(
|
632 |
Output('loe-output', 'children'),
|
633 |
Input('generate-loe', 'n_clicks'),
|
634 |
-
|
635 |
State('upload-loe', 'filename'),
|
636 |
-
State('shred-output', 'children')
|
|
|
637 |
)
|
638 |
def update_loe_output(n_clicks, upload_contents, upload_filename, shred_output):
|
639 |
-
|
|
|
|
|
|
|
640 |
return "Click 'Generate LOE' to begin."
|
641 |
|
642 |
try:
|
643 |
-
if
|
644 |
-
|
645 |
-
|
646 |
-
|
|
|
|
|
|
|
647 |
else:
|
648 |
-
return "
|
649 |
|
650 |
if isinstance(loe_text, str) and loe_text.startswith(("Unsupported file format", "Error processing document", "The document appears to be empty")):
|
651 |
return loe_text
|
|
|
10 |
from io import BytesIO
|
11 |
import dash
|
12 |
import dash_bootstrap_components as dbc
|
13 |
+
from dash import html, dcc, Input, Output, State, ctx, dash_table, callback_context
|
14 |
import google.generativeai as genai
|
15 |
from docx import Document
|
16 |
from docx.shared import Pt
|
|
|
631 |
@app.callback(
|
632 |
Output('loe-output', 'children'),
|
633 |
Input('generate-loe', 'n_clicks'),
|
634 |
+
Input('upload-loe', 'contents'),
|
635 |
State('upload-loe', 'filename'),
|
636 |
+
State('shred-output', 'children'),
|
637 |
+
prevent_initial_call=True
|
638 |
)
|
639 |
def update_loe_output(n_clicks, upload_contents, upload_filename, shred_output):
|
640 |
+
ctx = callback_context
|
641 |
+
triggered_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
642 |
+
|
643 |
+
if not ctx.triggered:
|
644 |
return "Click 'Generate LOE' to begin."
|
645 |
|
646 |
try:
|
647 |
+
if triggered_id == 'generate-loe':
|
648 |
+
if upload_contents:
|
649 |
+
loe_text, loe_df = generate_loe(upload_contents, is_file=True, filename=upload_filename)
|
650 |
+
elif shred_output:
|
651 |
+
loe_text, loe_df = generate_loe(shred_output)
|
652 |
+
else:
|
653 |
+
return "Please upload a document or complete the Shred tab first."
|
654 |
else:
|
655 |
+
return "Click 'Generate LOE' to begin."
|
656 |
|
657 |
if isinstance(loe_text, str) and loe_text.startswith(("Unsupported file format", "Error processing document", "The document appears to be empty")):
|
658 |
return loe_text
|