ll7098ll commited on
Commit
27de525
·
verified ·
1 Parent(s): 270bca0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -90
app.py CHANGED
@@ -1,103 +1,67 @@
1
- """
2
- Install the Google AI Python SDK
3
-
4
- $ pip install google-generativeai
5
-
6
- See the getting started guide for more information:
7
- https://ai.google.dev/gemini-api/docs/get-started/python
8
- """
9
-
10
  import os
11
  import time
 
12
 
13
  import google.generativeai as genai
14
- import gradio as gr
15
 
16
- # Gemini API 키 설정
17
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
18
 
19
- # 모델 설정
 
20
  generation_config = {
21
- "temperature": 1,
22
- "top_p": 0.95,
23
- "top_k": 64,
24
- "max_output_tokens": 8192,
25
- "response_mime_type": "text/plain",
26
  }
 
27
  model = genai.GenerativeModel(
28
- model_name="gemini-1.5-pro",
29
- generation_config=generation_config,
 
 
30
  )
31
 
32
- def generate_research_plan(question):
33
- """
34
- 주어진 질문에 대한 통합 탐구 계획을 생성합니다.
35
-
36
- Args:
37
- question (str): 탐구할 질문
38
-
39
- Returns:
40
- str: 생성된 통합 탐구 계획
41
- """
42
-
43
- prompts = [
44
- "과학자로서 통합탐구의 절차에 따라 실험을 설계하고 예상되는 결과를 설명해",
45
- "질문 ",
46
- "통합탐구 과정 변인 통제",
47
- "질문 ",
48
- "통합탐구 과정 자료 해석 방법 및 절차",
49
- "질문 ",
50
- "통합탐구 과정 결론 도출 방법 및 절차",
51
- "질문 ",
52
- "통합탐구 과정 예상되는 일반화",
53
- "질문 문제 상황 질문",
54
- "통합탐구 과정 문제 인식",
55
- "질문 ",
56
- "통합탐구 과정 가설 설정",
57
- "질문 ",
58
- "통합탐구 과정 "
59
- ]
60
- prompts[1] = question
61
- prompts[13] = question
62
-
63
- response = model.generate_content(
64
- prompts
65
- )
66
-
67
- return response.text
68
-
69
- def stream_output(question):
70
- """
71
- 통합 탐구 계획 생성을 실시간으로 출력합니다.
72
-
73
- Args:
74
- question (str): 탐구할 질문
75
-
76
- Yields:
77
- str: 생성된 텍스트 조각
78
- """
79
-
80
- response = generate_research_plan(question)
81
- for chunk in response.split("\n"):
82
- yield chunk + "\n"
83
- time.sleep(0.05) # 출력 속도 조절
84
-
85
- with gr.Blocks() as demo:
86
- gr.Markdown("# 🧪 통합 탐구 계획 생성기")
87
- with gr.Row():
88
- with gr.Column():
89
- question = gr.Textbox(
90
- lines=5,
91
- label="🔬 탐구하고 싶은 질문을 입력하세요:",
92
- placeholder="예: 색깔마다 에너지가 달라서 옷 색깔에 따라 마르는 속도가 다를까?",
93
- )
94
- submit_btn = gr.Button("🚀 계획 생성!")
95
- with gr.Column():
96
- plan_output = gr.Textbox(
97
- lines=15,
98
- label="📝 생성된 통합 탐구 계획:",
99
- )
100
-
101
- submit_btn.click(fn=stream_output, inputs=question, outputs=plan_output)
102
 
103
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import time
3
+ import gradio as gr
4
 
5
  import google.generativeai as genai
 
6
 
 
7
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
8
 
9
+ # Create the model
10
+ # See https://ai.google.dev/api/python/google/generativeai/GenerativeModel
11
  generation_config = {
12
+ "temperature": 1,
13
+ "top_p": 0.95,
14
+ "top_k": 64,
15
+ "max_output_tokens": 8192,
16
+ "response_mime_type": "text/plain",
17
  }
18
+
19
  model = genai.GenerativeModel(
20
+ model_name="gemini-1.5-pro",
21
+ generation_config=generation_config,
22
+ # safety_settings = Adjust safety settings
23
+ # See https://ai.google.dev/gemini-api/docs/safety-settings
24
  )
25
 
26
+ def generate_research_plan(question, progress=gr.Progress(0, 1, label="생성 중...")):
27
+ """
28
+ 질문이나 탐구주제를 입력받아 통합탐구 계획을 생성하는 함수
29
+ """
30
+
31
+ # 프롬프트를 여러 부분으로 나누어 실시간 출력에 활용
32
+ prompts = [
33
+ "과학자로서 통합탐구의 절차에 따라 실험을 구체적, 단계적, 체계적으로 설계하고 예상되는 결과를 설명해줘.\n\n",
34
+ "질문 문제 상황 질문:\n\n",
35
+ question + "\n\n",
36
+ "통합탐구 과정 1. 문제 인식\n\n2. 가설 설정\n\n3. 변인 통제\n\n4. 자료 해석 방법 및 절차\n\n5. 결론 도출 방법 및 절차\n\n6. 예상되는 일반화\n\n7. 탐구를 위한 팁\n\n",
37
+ "질문:\n\n",
38
+ question + "\n\n",
39
+ "통합탐구 과정:\n\n"
40
+ ]
41
+
42
+ response_text = ""
43
+ for i, prompt in enumerate(prompts):
44
+ response_text += prompt
45
+ yield response_text # 현재까지 생성된 텍스트를 출력
46
+ time.sleep(0.1) # 약간의 지연 추가
47
+ progress.update(i / len(prompts)) # 진행 상태 업데이트
48
+
49
+ response = model.generate_content([response_text])
50
+
51
+ # 모델 응답을 실시간으로 출력
52
+ for chunk in response.text.split(" "):
53
+ response_text += chunk + " "
54
+ yield response_text
55
+ time.sleep(0.05)
56
+
57
+ # Gradio 인터페이스 생성
58
+ iface = gr.Interface(
59
+ fn=generate_research_plan,
60
+ inputs=gr.Textbox(lines=5, label="질문이나 탐구주제를 입력하세요"),
61
+ outputs=gr.Textbox(lines=10, label="통합탐구 계획"),
62
+ title="🔬 통합탐구 계획 생성기",
63
+ description="과학 탐구 주제에 대한 자세한 계획을 세우세요!"
64
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ # 인터페이스 실행
67
+ iface.launch()