Update page_files/Upload_Data.py
Browse files- page_files/Upload_Data.py +11 -12
page_files/Upload_Data.py
CHANGED
|
@@ -101,7 +101,7 @@ def _df_to_meta(df: pd.DataFrame) -> dict:
|
|
| 101 |
"material_abbreviation": str(row0.get("material_abbreviation", "")),
|
| 102 |
"trade_grade": str(row0.get("trade_grade", "")),
|
| 103 |
"manufacturer": str(row0.get("manufacturer", "")),
|
| 104 |
-
"
|
| 105 |
"mechanical_properties": props,
|
| 106 |
}
|
| 107 |
|
|
@@ -543,7 +543,7 @@ def render_material_data_tab(pdf_path: str):
|
|
| 543 |
unsafe_allow_html=True,
|
| 544 |
)
|
| 545 |
timer.caption(
|
| 546 |
-
f" Elapsed: {elapsed:.0f}s"
|
| 547 |
+ (f" · Est. remaining: ~{est_remaining}s" if est_remaining > 0 else "")
|
| 548 |
)
|
| 549 |
|
|
@@ -554,12 +554,11 @@ def render_material_data_tab(pdf_path: str):
|
|
| 554 |
data = call_gemini_from_bytes(pdf_bytes)
|
| 555 |
df = convert_to_dataframe(data)
|
| 556 |
|
| 557 |
-
# DOI — regex over the PDF text,
|
| 558 |
-
# column category_push preserves into <table>_extras.
|
| 559 |
doi = _extract_doi_from_pdf(pdf_bytes)
|
|
|
|
| 560 |
if not df.empty:
|
| 561 |
-
df["
|
| 562 |
-
df["doi_url"] = doi
|
| 563 |
|
| 564 |
if not df.empty:
|
| 565 |
_cb("Verifying against source PDF…", 0.70)
|
|
@@ -576,7 +575,7 @@ def render_material_data_tab(pdf_path: str):
|
|
| 576 |
st.session_state.pdf_extracted_df = df
|
| 577 |
st.session_state.pdf_data_extracted = True
|
| 578 |
st.session_state.pdf_extracted_meta = _df_to_meta(df)
|
| 579 |
-
st.session_state.pdf_doi =
|
| 580 |
st.success(f" Extracted {len(df)} properties in {elapsed_total:.0f}s")
|
| 581 |
else:
|
| 582 |
st.warning("No data extracted from PDF.")
|
|
@@ -720,7 +719,7 @@ def render_plots_tab(pdf_path: str, paper_id: str):
|
|
| 720 |
if has_data:
|
| 721 |
cA, cB = st.columns([0.6, 0.4])
|
| 722 |
run_map = cA.button(
|
| 723 |
-
"
|
| 724 |
type="primary",
|
| 725 |
disabled=st.session_state.get("mapping_done", False),
|
| 726 |
use_container_width=True,
|
|
@@ -752,8 +751,8 @@ def render_plots_tab(pdf_path: str, paper_id: str):
|
|
| 752 |
|
| 753 |
# 3) Figure-centric review — each figure with delete/remove controls and
|
| 754 |
# (after mapping) the property rows linked to it.
|
| 755 |
-
st.caption("Review the crops below. Remove a bad crop with **
|
| 756 |
-
"figure with **
|
| 757 |
"mapping afterwards.")
|
| 758 |
for gi, group in enumerate(plot_results):
|
| 759 |
caption = group.get("caption", f"Figure {gi+1}")
|
|
@@ -763,7 +762,7 @@ def render_plots_tab(pdf_path: str, paper_id: str):
|
|
| 763 |
with st.container(border=True):
|
| 764 |
head, dele = st.columns([0.85, 0.15])
|
| 765 |
head.markdown(f"**Page {page}** — {caption}")
|
| 766 |
-
if dele.button(" Delete ", key=f"delfig_{gi}", use_container_width=True):
|
| 767 |
plot_results.pop(gi)
|
| 768 |
st.session_state.plot_results = plot_results
|
| 769 |
_reset_plot_mapping()
|
|
@@ -845,7 +844,7 @@ def render_plots_tab(pdf_path: str, paper_id: str):
|
|
| 845 |
"attaches each crop's path. Push conforms those rows to the chosen "
|
| 846 |
"category table's 33-column schema and uploads them.")
|
| 847 |
|
| 848 |
-
if st.button("Store to database (SQLite)", use_container_width=True):
|
| 849 |
with st.spinner("Saving crops and writing SQLite…"):
|
| 850 |
st.session_state.store = mapper5.store_properties_with_plots(
|
| 851 |
st.session_state.df_aug,
|
|
|
|
| 101 |
"material_abbreviation": str(row0.get("material_abbreviation", "")),
|
| 102 |
"trade_grade": str(row0.get("trade_grade", "")),
|
| 103 |
"manufacturer": str(row0.get("manufacturer", "")),
|
| 104 |
+
"doi_url": str(row0.get("doi_url", "")),
|
| 105 |
"mechanical_properties": props,
|
| 106 |
}
|
| 107 |
|
|
|
|
| 543 |
unsafe_allow_html=True,
|
| 544 |
)
|
| 545 |
timer.caption(
|
| 546 |
+
f"⏱ Elapsed: {elapsed:.0f}s"
|
| 547 |
+ (f" · Est. remaining: ~{est_remaining}s" if est_remaining > 0 else "")
|
| 548 |
)
|
| 549 |
|
|
|
|
| 554 |
data = call_gemini_from_bytes(pdf_bytes)
|
| 555 |
df = convert_to_dataframe(data)
|
| 556 |
|
| 557 |
+
# DOI — regex over the PDF text, stored as a full URL (single column).
|
|
|
|
| 558 |
doi = _extract_doi_from_pdf(pdf_bytes)
|
| 559 |
+
doi_url = f"https://doi.org/{doi}" if doi else ""
|
| 560 |
if not df.empty:
|
| 561 |
+
df["doi_url"] = doi_url
|
|
|
|
| 562 |
|
| 563 |
if not df.empty:
|
| 564 |
_cb("Verifying against source PDF…", 0.70)
|
|
|
|
| 575 |
st.session_state.pdf_extracted_df = df
|
| 576 |
st.session_state.pdf_data_extracted = True
|
| 577 |
st.session_state.pdf_extracted_meta = _df_to_meta(df)
|
| 578 |
+
st.session_state.pdf_doi = doi_url
|
| 579 |
st.success(f" Extracted {len(df)} properties in {elapsed_total:.0f}s")
|
| 580 |
else:
|
| 581 |
st.warning("No data extracted from PDF.")
|
|
|
|
| 719 |
if has_data:
|
| 720 |
cA, cB = st.columns([0.6, 0.4])
|
| 721 |
run_map = cA.button(
|
| 722 |
+
" Map properties → figures",
|
| 723 |
type="primary",
|
| 724 |
disabled=st.session_state.get("mapping_done", False),
|
| 725 |
use_container_width=True,
|
|
|
|
| 751 |
|
| 752 |
# 3) Figure-centric review — each figure with delete/remove controls and
|
| 753 |
# (after mapping) the property rows linked to it.
|
| 754 |
+
st.caption("Review the crops below. Remove a bad crop with ** **, or drop a whole "
|
| 755 |
+
"figure with ** **. Editing figures clears the current mapping — re-run "
|
| 756 |
"mapping afterwards.")
|
| 757 |
for gi, group in enumerate(plot_results):
|
| 758 |
caption = group.get("caption", f"Figure {gi+1}")
|
|
|
|
| 762 |
with st.container(border=True):
|
| 763 |
head, dele = st.columns([0.85, 0.15])
|
| 764 |
head.markdown(f"**Page {page}** — {caption}")
|
| 765 |
+
if dele.button(" Delete figure", key=f"delfig_{gi}", use_container_width=True):
|
| 766 |
plot_results.pop(gi)
|
| 767 |
st.session_state.plot_results = plot_results
|
| 768 |
_reset_plot_mapping()
|
|
|
|
| 844 |
"attaches each crop's path. Push conforms those rows to the chosen "
|
| 845 |
"category table's 33-column schema and uploads them.")
|
| 846 |
|
| 847 |
+
if st.button(" Store to database (SQLite)", use_container_width=True):
|
| 848 |
with st.spinner("Saving crops and writing SQLite…"):
|
| 849 |
st.session_state.store = mapper5.store_properties_with_plots(
|
| 850 |
st.session_state.df_aug,
|