Aye10032
commited on
Commit
·
4da16c7
1
Parent(s):
1ea26ce
update
Browse files- pages/AcademicTranslate.py +17 -0
pages/AcademicTranslate.py
CHANGED
@@ -14,6 +14,12 @@ st.set_page_config(
|
|
14 |
|
15 |
st.title("学术中英互译")
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
with st.sidebar:
|
18 |
side_bar_links()
|
19 |
|
@@ -23,9 +29,14 @@ with st.sidebar:
|
|
23 |
else:
|
24 |
st.caption('zh → en')
|
25 |
|
|
|
|
|
26 |
if 'ac_translate_history' not in st.session_state:
|
27 |
st.session_state.ac_translate_history = []
|
28 |
|
|
|
|
|
|
|
29 |
chat_container = st.container(height=610, border=False)
|
30 |
|
31 |
with chat_container:
|
@@ -34,6 +45,9 @@ with chat_container:
|
|
34 |
with st.chat_message(message['role']):
|
35 |
st.markdown(message['content'])
|
36 |
|
|
|
|
|
|
|
37 |
|
38 |
def ac_translate(original_text: str, is_en2zh: bool):
|
39 |
if is_en2zh:
|
@@ -76,3 +90,6 @@ if prompt := st.chat_input():
|
|
76 |
response = ac_translate(prompt, st.session_state.get('is_en2zh'))
|
77 |
translate_result = chat_container.chat_message("ai").write_stream(response)
|
78 |
st.session_state.ac_translate_history.append({'role': 'assistant', 'content': translate_result})
|
|
|
|
|
|
|
|
14 |
|
15 |
st.title("学术中英互译")
|
16 |
|
17 |
+
|
18 |
+
def clean_screen():
|
19 |
+
st.session_state.ac_translate_history = []
|
20 |
+
st.rerun()
|
21 |
+
|
22 |
+
|
23 |
with st.sidebar:
|
24 |
side_bar_links()
|
25 |
|
|
|
29 |
else:
|
30 |
st.caption('zh → en')
|
31 |
|
32 |
+
st.button("清屏", on_click=clean_screen)
|
33 |
+
|
34 |
if 'ac_translate_history' not in st.session_state:
|
35 |
st.session_state.ac_translate_history = []
|
36 |
|
37 |
+
if 'ac_code_text' not in st.session_state:
|
38 |
+
st.session_state.ac_code_text = ''
|
39 |
+
|
40 |
chat_container = st.container(height=610, border=False)
|
41 |
|
42 |
with chat_container:
|
|
|
45 |
with st.chat_message(message['role']):
|
46 |
st.markdown(message['content'])
|
47 |
|
48 |
+
with st.container(height=150,border=False):
|
49 |
+
st.code(st.session_state.ac_code_text, 'markdown')
|
50 |
+
|
51 |
|
52 |
def ac_translate(original_text: str, is_en2zh: bool):
|
53 |
if is_en2zh:
|
|
|
90 |
response = ac_translate(prompt, st.session_state.get('is_en2zh'))
|
91 |
translate_result = chat_container.chat_message("ai").write_stream(response)
|
92 |
st.session_state.ac_translate_history.append({'role': 'assistant', 'content': translate_result})
|
93 |
+
st.session_state.ac_code_text = translate_result
|
94 |
+
|
95 |
+
st.rerun()
|