ll7098ll commited on
Commit
940b028
·
verified ·
1 Parent(s): 401ecd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import os
2
  import google.generativeai as genai
3
- import time
4
  import gradio as gr
5
 
6
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
 
 
8
  generation_config = {
9
  "temperature": 1,
10
  "top_p": 0.95,
@@ -35,7 +35,7 @@ model = genai.GenerativeModel(model_name="gemini-1.5-pro",
35
  generation_config=generation_config,
36
  safety_settings=safety_settings)
37
 
38
- def generate_curriculum(prompt):
39
  prompt_parts = [
40
  "Concept-Based Curriculum Expert, If your answer is good, I'll give you a $10 tip.",
41
  "성취기준 성취 기준 및 수업 목표",
@@ -45,21 +45,14 @@ def generate_curriculum(prompt):
45
  ]
46
 
47
  response = model.generate_content(prompt_parts)
48
- return response.text
49
-
50
- def chat_bot(message, history):
51
- history.append((message, ""))
52
- if message:
53
- response = generate_curriculum(message)
54
- for char in response:
55
- history[-1] = (message, history[-1][1] + char)
56
- yield history
57
- time.sleep(0.05) # Adjust the delay as needed
58
- history[-1] = (message, response)
59
- yield history
60
-
61
- iface = gr.ChatInterface(
62
- fn=chat_bot,
63
  title="개념 기반 교육과정 챗봇",
64
  description="성취기준을 입력하면 개념 기반 교육과정을 생성합니다."
65
  )
 
1
  import os
2
  import google.generativeai as genai
 
3
  import gradio as gr
4
 
5
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
6
 
7
+ # Set up the model
8
  generation_config = {
9
  "temperature": 1,
10
  "top_p": 0.95,
 
35
  generation_config=generation_config,
36
  safety_settings=safety_settings)
37
 
38
+ def generate_curriculum(prompt, history=[]):
39
  prompt_parts = [
40
  "Concept-Based Curriculum Expert, If your answer is good, I'll give you a $10 tip.",
41
  "성취기준 성취 기준 및 수업 목표",
 
45
  ]
46
 
47
  response = model.generate_content(prompt_parts)
48
+
49
+ # 스트리밍 출력을 위한 처리
50
+ yield from response.iter_chunks()
51
+
52
+ iface = gr.Interface(
53
+ fn=generate_curriculum,
54
+ inputs=gr.Textbox(lines=1, label="성취기준 입력"),
55
+ outputs=gr.Chatbot(label="개념 기반 교육과정"),
 
 
 
 
 
 
 
56
  title="개념 기반 교육과정 챗봇",
57
  description="성취기준을 입력하면 개념 기반 교육과정을 생성합니다."
58
  )