Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -136,10 +136,12 @@ def markdown_table_to_df(md_table):
|
|
136 |
|
137 |
def markdown_table_preview(md_text):
|
138 |
if not md_text:
|
139 |
-
|
|
|
140 |
tables = extract_markdown_tables(md_text)
|
141 |
if not tables:
|
142 |
-
|
|
|
143 |
table_divs = []
|
144 |
for i, table in enumerate(tables):
|
145 |
df = markdown_table_to_df(table)
|
@@ -157,10 +159,17 @@ def markdown_table_preview(md_text):
|
|
157 |
)
|
158 |
], className="mb-4")
|
159 |
)
|
|
|
|
|
|
|
|
|
160 |
return html.Div(table_divs)
|
161 |
|
162 |
def markdown_narrative_preview(md_text):
|
163 |
-
|
|
|
|
|
|
|
164 |
|
165 |
def markdown_tables_to_xlsx(md_text):
|
166 |
tables = extract_markdown_tables(md_text)
|
@@ -585,6 +594,7 @@ def unified_handler(contents_lists, n_clicks_generate_list, n_clicks_download, s
|
|
585 |
name = filenames[-1]
|
586 |
file_text = process_document(content, name)
|
587 |
logging.info(f"Processed uploaded file for subtype '{subtype}': {name}")
|
|
|
588 |
set_uploaded_doc(subtype, file_text, name)
|
589 |
stores[idx] = file_text
|
590 |
if subtype == "shred":
|
@@ -635,6 +645,7 @@ def unified_handler(contents_lists, n_clicks_generate_list, n_clicks_download, s
|
|
635 |
else:
|
636 |
context += f"\n\n{inputs.get('shred','')}"
|
637 |
full_prompt = f"{prompt}\n\n{context}"
|
|
|
638 |
result_holder = {}
|
639 |
|
640 |
def gemini_thread():
|
@@ -700,12 +711,6 @@ def unified_handler(contents_lists, n_clicks_generate_list, n_clicks_download, s
|
|
700 |
download_data = dcc.send_bytes(content, filename=f"{selected_type}_output.md")
|
701 |
return stores + [file_list, uploaded_doc_name_shred, dash.no_update, dash.no_update, download_data, loader_trigger]
|
702 |
|
703 |
-
# Fallback: test preview with hardcoded table if Shred and no doc
|
704 |
-
if selected_type == "Shred" and not stores[0]:
|
705 |
-
logging.info("Testing preview with hardcoded markdown table (Shred, no doc).")
|
706 |
-
preview = markdown_table_preview("| Col1 | Col2 |\n|---|---|\n| a | b |")
|
707 |
-
return stores + [file_list, uploaded_doc_name_shred, preview, dash.no_update, dash.no_update, loader_trigger]
|
708 |
-
|
709 |
# Default preview logic
|
710 |
doc = prev_generated
|
711 |
if not doc:
|
@@ -737,19 +742,9 @@ def unified_handler(contents_lists, n_clicks_generate_list, n_clicks_download, s
|
|
737 |
doc = doc_store.get(selected_type, "")
|
738 |
preview = markdown_narrative_preview(doc)
|
739 |
else:
|
740 |
-
logging.warning("No document content found for preview.")
|
741 |
preview = html.Div("No document loaded or generated.")
|
742 |
|
743 |
-
return stores + [file_list, uploaded_doc_name_shred, preview,
|
744 |
-
|
745 |
-
@app.callback(
|
746 |
-
Output("main-progress-dot-output", "children"),
|
747 |
-
Input('main-loader-trigger', 'data')
|
748 |
-
)
|
749 |
-
def update_main_progress_dot(progress):
|
750 |
-
return ""
|
751 |
|
752 |
-
if __name__ ==
|
753 |
-
|
754 |
-
app.run(debug=True, host='0.0.0.0', port=7860, threaded=True)
|
755 |
-
print("Dash application has finished running.")
|
|
|
136 |
|
137 |
def markdown_table_preview(md_text):
|
138 |
if not md_text:
|
139 |
+
logging.warning("No markdown text provided for preview.")
|
140 |
+
return html.Div("No preview available.")
|
141 |
tables = extract_markdown_tables(md_text)
|
142 |
if not tables:
|
143 |
+
logging.warning("No tables found in markdown text.")
|
144 |
+
return html.Div("No tables to preview.")
|
145 |
table_divs = []
|
146 |
for i, table in enumerate(tables):
|
147 |
df = markdown_table_to_df(table)
|
|
|
159 |
)
|
160 |
], className="mb-4")
|
161 |
)
|
162 |
+
else:
|
163 |
+
logging.warning(f"Table {i} could not be parsed into DataFrame.")
|
164 |
+
if not table_divs:
|
165 |
+
return html.Div("No valid tables to preview.")
|
166 |
return html.Div(table_divs)
|
167 |
|
168 |
def markdown_narrative_preview(md_text):
|
169 |
+
if not md_text:
|
170 |
+
logging.warning("No markdown text provided for narrative preview.")
|
171 |
+
return html.Div("No preview available.")
|
172 |
+
return html.Div(dcc.Markdown(md_text, dangerously_allow_html=True, style={'whiteSpace': 'pre-wrap', 'fontFamily': 'sans-serif'}))
|
173 |
|
174 |
def markdown_tables_to_xlsx(md_text):
|
175 |
tables = extract_markdown_tables(md_text)
|
|
|
594 |
name = filenames[-1]
|
595 |
file_text = process_document(content, name)
|
596 |
logging.info(f"Processed uploaded file for subtype '{subtype}': {name}")
|
597 |
+
logging.info(f"Extracted text from uploaded document (first 500 chars): {file_text[:500]}")
|
598 |
set_uploaded_doc(subtype, file_text, name)
|
599 |
stores[idx] = file_text
|
600 |
if subtype == "shred":
|
|
|
645 |
else:
|
646 |
context += f"\n\n{inputs.get('shred','')}"
|
647 |
full_prompt = f"{prompt}\n\n{context}"
|
648 |
+
logging.info(f"Prompt sent to Gemini (first 1000 chars): {full_prompt[:1000]}")
|
649 |
result_holder = {}
|
650 |
|
651 |
def gemini_thread():
|
|
|
711 |
download_data = dcc.send_bytes(content, filename=f"{selected_type}_output.md")
|
712 |
return stores + [file_list, uploaded_doc_name_shred, dash.no_update, dash.no_update, download_data, loader_trigger]
|
713 |
|
|
|
|
|
|
|
|
|
|
|
|
|
714 |
# Default preview logic
|
715 |
doc = prev_generated
|
716 |
if not doc:
|
|
|
742 |
doc = doc_store.get(selected_type, "")
|
743 |
preview = markdown_narrative_preview(doc)
|
744 |
else:
|
|
|
745 |
preview = html.Div("No document loaded or generated.")
|
746 |
|
747 |
+
return stores + [file_list, uploaded_doc_name_shred, preview, dash.no_update, dash.no_update, loader_trigger]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
748 |
|
749 |
+
if __name__ == "__main__":
|
750 |
+
app.run_server(debug=True)
|
|
|
|