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