Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- README.md +4 -4
- app.py +35 -15
- requirements.txt +2 -1
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
sdk: streamlit
|
| 4 |
-
emoji:
|
| 5 |
app_file: app.py
|
| 6 |
---
|
| 7 |
|
| 8 |
-
#
|
| 9 |
|
| 10 |
-
使用 Hugging Face
|
|
|
|
| 1 |
---
|
| 2 |
+
title: DeepSeek 教案生成器
|
| 3 |
sdk: streamlit
|
| 4 |
+
emoji: 📘
|
| 5 |
app_file: app.py
|
| 6 |
---
|
| 7 |
|
| 8 |
+
# 教案生成器(DeepSeek AI 模型)
|
| 9 |
|
| 10 |
+
使用 deepseek-ai/deepseek-llm-7b-chat 模型,通过 Hugging Face Inference API 实现结构化教案生成,适配中文教学环境。
|
app.py
CHANGED
|
@@ -1,45 +1,65 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
st.set_page_config(page_title="
|
| 5 |
-
st.title("📘 英语教案生成器(
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
client = InferenceClient("
|
| 9 |
|
| 10 |
def generate_response(message):
|
| 11 |
-
system_prompt = "
|
| 12 |
full_prompt = f"""<|system|>{system_prompt}
|
| 13 |
<|user|>{message}
|
| 14 |
<|assistant|>"""
|
| 15 |
response = client.text_generation(
|
| 16 |
prompt=full_prompt,
|
| 17 |
-
max_new_tokens=
|
| 18 |
temperature=0.7,
|
| 19 |
stop_sequences=["<|user|>", "<|system|>"]
|
| 20 |
)
|
| 21 |
return response.strip()
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
theme = st.text_input("请输入教案主题(如:School)")
|
| 25 |
vocab = st.text_area("请输入目标词汇(英文逗号分隔)", placeholder="grammar, Geography, exam, report...")
|
| 26 |
submit = st.button("生成教案")
|
| 27 |
|
| 28 |
if submit and theme and vocab:
|
| 29 |
-
with st.spinner("
|
| 30 |
user_prompt = f"""请根据以下要求生成一份初中英语教案:
|
| 31 |
|
| 32 |
- 教案主题:{theme}
|
| 33 |
- 目标词汇:{vocab}
|
| 34 |
|
| 35 |
-
|
| 36 |
-
1.
|
| 37 |
-
2.
|
| 38 |
-
3.
|
| 39 |
-
4.
|
| 40 |
-
5. 总结2
|
| 41 |
-
6.
|
| 42 |
"""
|
| 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="DeepSeek 教案生成器", layout="wide")
|
| 7 |
+
st.title("📘 英语教案生成器(DeepSeek 模型)")
|
| 8 |
|
| 9 |
+
# 指定 DeepSeek 模型
|
| 10 |
+
client = InferenceClient("deepseek-ai/deepseek-llm-7b-chat", provider="hf-inference")
|
| 11 |
|
| 12 |
def generate_response(message):
|
| 13 |
+
system_prompt = "你是一位经验丰富的初中英语老师,善于设计结构化、通俗易懂的英语教案。"
|
| 14 |
full_prompt = f"""<|system|>{system_prompt}
|
| 15 |
<|user|>{message}
|
| 16 |
<|assistant|>"""
|
| 17 |
response = client.text_generation(
|
| 18 |
prompt=full_prompt,
|
| 19 |
+
max_new_tokens=800,
|
| 20 |
temperature=0.7,
|
| 21 |
stop_sequences=["<|user|>", "<|system|>"]
|
| 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...")
|
| 38 |
submit = st.button("生成教案")
|
| 39 |
|
| 40 |
if submit and theme and vocab:
|
| 41 |
+
with st.spinner("正在调用 DeepSeek AI 生成教案..."):
|
| 42 |
user_prompt = f"""请根据以下要求生成一份初中英语教案:
|
| 43 |
|
| 44 |
- 教案主题:{theme}
|
| 45 |
- 目标词汇:{vocab}
|
| 46 |
|
| 47 |
+
结构要求:
|
| 48 |
+
1. 教学目标
|
| 49 |
+
2. 目标词汇解释
|
| 50 |
+
3. 一篇包含目标词汇的文章(适合初一学生阅读)
|
| 51 |
+
4. 用【】标出目标词汇,用(括号)说明语法点
|
| 52 |
+
5. 总结2个语法点
|
| 53 |
+
6. 提供2个课堂练习建议
|
| 54 |
"""
|
| 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
|