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,
|