| import os |
| import google.generativeai as genai |
| import time |
| import gradio as gr |
|
|
| genai.configure(api_key=os.environ["GEMINI_API_KEY"]) |
|
|
| generation_config = { |
| "temperature": 1, |
| "top_p": 0.95, |
| "top_k": 64, |
| "max_output_tokens": 8192, |
| } |
|
|
| safety_settings = [ |
| { |
| "category": "HARM_CATEGORY_HARASSMENT", |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" |
| }, |
| { |
| "category": "HARM_CATEGORY_HATE_SPEECH", |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" |
| }, |
| { |
| "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" |
| }, |
| { |
| "category": "HARM_CATEGORY_DANGEROUS_CONTENT", |
| "threshold": "BLOCK_MEDIUM_AND_ABOVE" |
| }, |
| ] |
|
|
| model = genai.GenerativeModel(model_name="gemini-1.5-pro", |
| generation_config=generation_config, |
| safety_settings=safety_settings) |
|
|
| def generate_curriculum(prompt): |
| prompt_parts = [ |
| "Concept-Based Curriculum Expert, If your answer is good, I'll give you a $10 tip.", |
| "성취기준 성취 기준 및 수업 목표", |
| "개념기반 교육과정 1. 핵심 아이디어(일반화된 지식)\n\n2. 매크로 개념(개념적 렌즈), 마이크로 개념(교과 개념)\n\n3. 사실적 지식, 주제, 개념, 원리 및 일반화, 이론\n\n4. 스트랜드와 차시별 학습활동\n\n5. 평가 내용 및 방법, 평가 루브릭(상, 중, 하 평어 예시 포함)\n\n6. 개념적 이해를 위한 팁", |
| prompt, |
| "개념기반 교육과정 ", |
| ] |
|
|
| response = model.generate_content(prompt_parts) |
| return response.text |
|
|
| def chat_bot(message, history): |
| history.append((message, "")) |
| if message: |
| response = generate_curriculum(message) |
| for char in response: |
| history[-1] = (message, history[-1][1] + char) |
| yield history |
| time.sleep(0.05) |
| history[-1] = (message, response) |
| yield history |
|
|
| iface = gr.ChatInterface( |
| fn=chat_bot, |
| title="개념 기반 교육과정 챗봇", |
| description="성취기준을 입력하면 개념 기반 교육과정을 생성합니다." |
| ) |
|
|
| iface.launch() |