Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 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 |
|
|
@@ -44,16 +45,17 @@ def generate_curriculum(prompt):
|
|
| 44 |
"개념기반 교육과정 ",
|
| 45 |
]
|
| 46 |
|
| 47 |
-
# "stream=True"를 추가하여 응답을 스트리밍 방식으로 받습니다.
|
| 48 |
-
response = model.generate_content(prompt_parts, stream=True)
|
| 49 |
-
|
| 50 |
-
# 전체 텍스트를 저장할 변수
|
| 51 |
full_text = ""
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
iface = gr.Interface(
|
| 59 |
fn=generate_curriculum,
|
|
|
|
| 1 |
import os
|
| 2 |
import google.generativeai as genai
|
| 3 |
import gradio as gr
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
| 7 |
|
|
|
|
| 45 |
"개념기반 교육과정 ",
|
| 46 |
]
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
full_text = ""
|
| 49 |
+
yield full_text # 초기 빈 텍스트 출력
|
| 50 |
|
| 51 |
+
try:
|
| 52 |
+
response = model.generate_content(prompt_parts, stream=True)
|
| 53 |
+
for chunk in response:
|
| 54 |
+
full_text += chunk.text
|
| 55 |
+
yield full_text
|
| 56 |
+
time.sleep(0.05) # 약간의 지연 추가
|
| 57 |
+
except Exception as e:
|
| 58 |
+
yield f"에러 발생: {str(e)}"
|
| 59 |
|
| 60 |
iface = gr.Interface(
|
| 61 |
fn=generate_curriculum,
|