Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- README.md +1 -1
- app.py +20 -0
- requirements.txt +2 -1
README.md
CHANGED
|
@@ -7,4 +7,4 @@ app_file: app.py
|
|
| 7 |
|
| 8 |
# Chat型英语教案生成器
|
| 9 |
|
| 10 |
-
使用 Hugging Face 提供的聊天语言模型(Zephyr 7B),通过指令式 prompt
|
|
|
|
| 7 |
|
| 8 |
# Chat型英语教案生成器
|
| 9 |
|
| 10 |
+
使用 Hugging Face 提供的聊天语言模型(Zephyr 7B),通过指令式 prompt 快速生成结构化英语教案。支持导出 Word。无需 API Key,无需部署模型。
|
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="英语教案Chat生成器", layout="wide")
|
| 5 |
st.title("📘 英语教案生成器(Chat模型版)")
|
|
@@ -20,6 +22,16 @@ def generate_response(message):
|
|
| 20 |
)
|
| 21 |
return response.strip()
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# 输入框
|
| 24 |
theme = st.text_input("请输入教案主题(如:School)")
|
| 25 |
vocab = st.text_area("请输入目标词汇(英文逗号分隔)", placeholder="grammar, Geography, exam, report...")
|
|
@@ -43,3 +55,11 @@ if submit and theme and vocab:
|
|
| 43 |
result = generate_response(user_prompt)
|
| 44 |
st.markdown("### 📄 教案生成结果")
|
| 45 |
st.markdown(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
from docx import Document
|
| 4 |
+
from io import BytesIO
|
| 5 |
|
| 6 |
st.set_page_config(page_title="英语教案Chat生成器", layout="wide")
|
| 7 |
st.title("📘 英语教案生成器(Chat模型版)")
|
|
|
|
| 22 |
)
|
| 23 |
return response.strip()
|
| 24 |
|
| 25 |
+
def create_word_file(content, title="lesson_plan"):
|
| 26 |
+
doc = Document()
|
| 27 |
+
doc.add_heading("英语教案", 0)
|
| 28 |
+
for line in content.split("\n"):
|
| 29 |
+
doc.add_paragraph(line)
|
| 30 |
+
file_stream = BytesIO()
|
| 31 |
+
doc.save(file_stream)
|
| 32 |
+
file_stream.seek(0)
|
| 33 |
+
return file_stream
|
| 34 |
+
|
| 35 |
# 输入框
|
| 36 |
theme = st.text_input("请输入教案主题(如:School)")
|
| 37 |
vocab = st.text_area("请输入目标词汇(英文逗号分隔)", placeholder="grammar, Geography, exam, report...")
|
|
|
|
| 55 |
result = generate_response(user_prompt)
|
| 56 |
st.markdown("### 📄 教案生成结果")
|
| 57 |
st.markdown(result)
|
| 58 |
+
|
| 59 |
+
word_file = create_word_file(result)
|
| 60 |
+
st.download_button(
|
| 61 |
+
label="📥 下载教案(Word格式)",
|
| 62 |
+
data=word_file,
|
| 63 |
+
file_name=f"{theme}_lesson_plan.docx",
|
| 64 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
| 65 |
+
)
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
streamlit
|
| 2 |
-
huggingface_hub
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
+
huggingface_hub
|
| 3 |
+
python-docx
|