Spaces:
Sleeping
Sleeping

Refactor imports and update configuration for LLM response processing; add post-processing functionality and enhance README documentation.
25fca04
import streamlit as st | |
from prompt import get_llm_response | |
from post_process import process_response | |
# 页面配置 | |
st.set_page_config( | |
page_title="EnglishMate - 你的英语学习助手", | |
page_icon="⚡", | |
layout="wide" | |
) | |
# 页面标题 | |
st.title("EnglishMate - 你的英语学习助手 ⚡") | |
st.markdown("输入中文,获取地道的英语表达!") | |
# 用户输入区域 | |
example_text = "我昨天跟同学在西公园打篮球,我成功完成了一次暴扣。" | |
user_input = st.text_area("请输入你想用英语表达的内容:", value=example_text, height=150) | |
# 添加提交按钮 | |
if st.button("翻译"): | |
if user_input: | |
with st.spinner('正在生成英语表达...'): | |
# 调用LLM获取响应 | |
response = get_llm_response(user_input) | |
english_translation, important_words = process_response(response) | |
# 高亮重要单词 | |
for word in important_words: | |
english_translation = english_translation.replace( | |
word['word_en'], f"<mark>{word['word_en']}</mark>") | |
# 显示英语表达 | |
st.subheader("🔤 英语表达") | |
st.markdown(f"<h2>{english_translation}</h2>", | |
unsafe_allow_html=True) | |
# 显示重要单词 | |
st.subheader("📚 重要单词") | |
for word in important_words: | |
st.markdown(f"**{word['word_en']}** - {word['meaning_ch']}") | |
st.markdown(f"{word['usage']}") | |
# 添加页面底部说明 | |
st.markdown("---") | |
st.markdown("💡 提示:输入你想要用英语表达的中文内容,系统会帮你翻译成地道的英语表达,并分析重要词汇。") | |
# 添加侧边栏说明 | |
st.sidebar.markdown("### 使用说明") | |
st.sidebar.markdown("1. 在文本框中输入你想要翻译的中文内容。") | |
st.sidebar.markdown("2. 点击“翻译”按钮。") | |
st.sidebar.markdown("3. 查看生成的英语表达和重要单词。") | |