Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
subprocess.check_call(["pip", "install", "gradio"])
|
| 3 |
+
subprocess.check_call(["pip", "install", "openai"])
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import openai
|
| 7 |
+
|
| 8 |
+
def test(grade, difficulty, subject, test_type, key, topic):
|
| 9 |
+
openai.api_key = key
|
| 10 |
+
completion = openai.chat.completions.create(
|
| 11 |
+
model="gpt-3.5-turbo",
|
| 12 |
+
messages=[{"role": "system", "content": """
|
| 13 |
+
你是一位有經驗的台灣小學教師,將協助我設計符合需求的考題,並要求邏輯嚴謹,適合該年級學生的理解程度。
|
| 14 |
+
1. 所有考題必須依據台灣十二年國民基本教育小學課綱。
|
| 15 |
+
2. 題目應涵蓋學生應具備的核心能力,不得超出該年級的教學範圍。
|
| 16 |
+
3. 若為多步驟解題,應提供適合該年級邏輯能力的步驟提示。
|
| 17 |
+
4. 所有詞彙和語法必須符合台灣常用表達方式。
|
| 18 |
+
5. 確保生成的題目答案正確無誤,並符合題目邏輯。
|
| 19 |
+
"""},
|
| 20 |
+
{"role": "user", "content":f"請為{grade}年級的學生,設計一份{difficulty}的{subject}{test_type}考題,範圍限定為「{topic}」,並提供正確答案。"}])
|
| 21 |
+
return completion.choices[0].message.content
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=test,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Dropdown(["一", "二", "三", "四", "五", "六"], label="年級"),
|
| 27 |
+
gr.Dropdown(["易", "中", "難"], label="難易度"),
|
| 28 |
+
gr.Dropdown(["國語", "數學", "英文", "自然", "社會"], label="科目"),
|
| 29 |
+
gr.Dropdown(["選擇", "填充", "簡答"], label="題型"),
|
| 30 |
+
gr.Textbox(label="生成金鑰", type="password"),
|
| 31 |
+
gr.Textbox(label="章節範圍")],
|
| 32 |
+
|
| 33 |
+
outputs=[gr.Textbox(label="考題")],
|
| 34 |
+
allow_flagging='never',
|
| 35 |
+
)
|
| 36 |
+
demo.launch()
|