Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +19 -10
src/streamlit_app.py
CHANGED
|
@@ -595,27 +595,36 @@ if st.session_state.execute_batch_analysis and 'json_data_for_batch' in st.sessi
|
|
| 595 |
"analysis_result": response,
|
| 596 |
"context": retrieved_ctx
|
| 597 |
}
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 601 |
with results_container:
|
| 602 |
|
| 603 |
-
|
| 604 |
# 呈現 LLM 分析結果
|
| 605 |
is_high = any(x in response.lower() for x in ['high-risk detected!'])
|
| 606 |
is_medium = any(x in response.lower() for x in ['medium-risk detected!'])
|
| 607 |
if is_high:
|
| 608 |
-
|
|
|
|
|
|
|
| 609 |
with st.expander("序列內容 (JSON Format)"):
|
| 610 |
st.code(item["sequence_analyzed"], language='json')
|
| 611 |
st.error(item['analysis_result'])
|
| 612 |
st.markdown("---")
|
| 613 |
elif is_medium:
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
|
|
|
| 619 |
|
| 620 |
if item['context']:
|
| 621 |
with st.expander("參考 RAG 片段"): st.code(item['context'])
|
|
|
|
| 595 |
"analysis_result": response,
|
| 596 |
"context": retrieved_ctx
|
| 597 |
}
|
| 598 |
+
fieldnames = list(item[0].keys()) if data_list else []
|
| 599 |
+
output_string_buffer = io.StringIO()
|
| 600 |
+
writer = csv.DictWriter(
|
| 601 |
+
output_string_buffer,
|
| 602 |
+
fieldnames=fieldnames,
|
| 603 |
+
)
|
| 604 |
+
writer.writeheader()
|
| 605 |
+
writer.writerows(item)
|
| 606 |
+
csv_string = output_string_buffer.getvalue()
|
| 607 |
+
|
| 608 |
with results_container:
|
| 609 |
|
|
|
|
| 610 |
# 呈現 LLM 分析結果
|
| 611 |
is_high = any(x in response.lower() for x in ['high-risk detected!'])
|
| 612 |
is_medium = any(x in response.lower() for x in ['medium-risk detected!'])
|
| 613 |
if is_high:
|
| 614 |
+
b64 = base64.b64encode(csv_string.encode('utf-8'))
|
| 615 |
+
st.markdown(f'<a href="data:application/octet-stream;base64,{b64.decode()}" download="Log_{item['log_id']}.csv">Log #{item['log_id']} (HIGH RISK DETECTED)</a>', unsafe_allow_html=True)
|
| 616 |
+
|
| 617 |
with st.expander("序列內容 (JSON Format)"):
|
| 618 |
st.code(item["sequence_analyzed"], language='json')
|
| 619 |
st.error(item['analysis_result'])
|
| 620 |
st.markdown("---")
|
| 621 |
elif is_medium:
|
| 622 |
+
b64 = base64.b64encode(csv_string.encode('utf-8'))
|
| 623 |
+
st.markdown(f'<a href="data:application/octet-stream;base64,{b64.decode()}" download="Log_{item['log_id']}.csv">Log #{item['log_id']} (MEDIUM RISK DETECTED)</a>', unsafe_allow_html=True)
|
| 624 |
+
with st.expander("序列內容 (JSON Format)"):
|
| 625 |
+
st.code(item["sequence_analyzed"], language='json')
|
| 626 |
+
st.warning(item['analysis_result'])
|
| 627 |
+
st.markdown("---")
|
| 628 |
|
| 629 |
if item['context']:
|
| 630 |
with st.expander("參考 RAG 片段"): st.code(item['context'])
|