ll7098ll commited on
Commit
270bca0
·
verified ·
1 Parent(s): 8d31ab0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -36
app.py CHANGED
@@ -1,44 +1,103 @@
 
 
 
 
 
 
 
 
 
1
  import os
2
  import time
3
- import gradio as gr
4
  import google.generativeai as genai
 
5
 
 
6
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
 
8
- def generate_research_plan(question):
9
- """질문에 대한 연구 계획을 실시간으로 생성합니다."""
10
- full_prompt = f"""과학자로서 통합탐구의 절차에 따라 실험을 설계하고 예상되는 결과를 설명해줘.
11
-
12
- 질문: {question}
13
-
14
- ## 통합탐구 과정
15
- 1. **문제 인식**
16
- 2. **가설 설정**
17
- 3. **변인 통제**
18
- 4. **자료 해석 방법 및 절차**
19
- 5. **결론 도출 방법 및 절차**
20
- 6. **예상되는 일반화**
21
- 7. **탐구를 위한 팁**
22
- """
23
-
24
- response = genai.generate_content(
25
- model="gemini-1.5-pro",
26
- prompt=full_prompt,
27
- temperature=1,
28
- max_output_tokens=8192,
29
- yield_stream=True,
30
- )
31
-
32
- for chunk in response:
33
- yield chunk.text + "\n"
34
- time.sleep(0.05)
35
-
36
- iface = gr.Interface(
37
- fn=generate_research_plan,
38
- inputs=gr.Textbox(lines=5, placeholder="질문이나 주제를 입력하세요."),
39
- outputs=gr.Textbox(label="탐구 계획"),
40
- title="🧪 통합탐구 계획 생성기",
41
- description="질문을 입력하면 과학자처럼 단계별 연구 계획을 실시간으로 생성해 줍니다."
42
  )
43
 
44
- iface.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()