Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,8 @@ import time
|
|
| 5 |
|
| 6 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
| 7 |
|
| 8 |
-
# ๋ชจ๋ธ
|
| 9 |
-
def
|
| 10 |
generation_config = {
|
| 11 |
"temperature": 1,
|
| 12 |
"top_p": 0.95,
|
|
@@ -33,11 +33,14 @@ def generate_curriculum(prompt):
|
|
| 33 |
},
|
| 34 |
]
|
| 35 |
|
| 36 |
-
|
| 37 |
-
model = genai.GenerativeModel(model_name="gemini-1.5-pro",
|
| 38 |
generation_config=generation_config,
|
| 39 |
safety_settings=safety_settings)
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
prompt_parts = [
|
| 42 |
"Concept-Based Curriculum Expert, ๊ฐ๋
๊ธฐ๋ฐ๊ต์ก๊ณผ์ ์ค๊ณ ์ ๋ฌธ๊ฐ. ์ด๋ฑํ๊ต ๊ต์ก๊ณผ์ ๋ฒ์ ๋ด์์ ๊ฐ๋
๊ธฐ๋ฐ ๊ต์ก๊ณผ์ ๋ฐ ์์
์ ์ฒด๊ณ์ ์ผ๋ก ์ค๊ณ.",
|
| 43 |
"์ฑ์ทจ๊ธฐ์ค ์ฑ์ทจ ๊ธฐ์ค ๋ฐ ์์
๋ชฉํ",
|
|
@@ -54,11 +57,11 @@ def generate_curriculum(prompt):
|
|
| 54 |
for chunk in response:
|
| 55 |
full_text += chunk.text
|
| 56 |
yield full_text
|
| 57 |
-
|
| 58 |
except Exception as e:
|
| 59 |
yield f"์๋ฌ ๋ฐ์: {str(e)}"
|
| 60 |
|
| 61 |
-
# ์ธํฐํ์ด์ค ์ค์ (
|
| 62 |
iface = gr.Interface(
|
| 63 |
fn=generate_curriculum,
|
| 64 |
inputs=gr.Textbox(lines=1, label="์ฑ์ทจ๊ธฐ์ค ์
๋ ฅ"),
|
|
@@ -67,4 +70,4 @@ iface = gr.Interface(
|
|
| 67 |
description="์ฑ์ทจ๊ธฐ์ค์ ์
๋ ฅํ๋ฉด ๊ฐ๋
๊ธฐ๋ฐ ๊ต์ก๊ณผ์ ์ ์ค๊ณํฉ๋๋ค."
|
| 68 |
)
|
| 69 |
|
| 70 |
-
iface.launch()
|
|
|
|
| 5 |
|
| 6 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
| 7 |
|
| 8 |
+
# ๋ชจ๋ธ ์์ฑ ํจ์ (๋งค ์์ฒญ๋ง๋ค ์๋ก์ด ๋ชจ๋ธ ์์ฑ)
|
| 9 |
+
def create_model():
|
| 10 |
generation_config = {
|
| 11 |
"temperature": 1,
|
| 12 |
"top_p": 0.95,
|
|
|
|
| 33 |
},
|
| 34 |
]
|
| 35 |
|
| 36 |
+
return genai.GenerativeModel(model_name="gemini-1.5-pro",
|
|
|
|
| 37 |
generation_config=generation_config,
|
| 38 |
safety_settings=safety_settings)
|
| 39 |
|
| 40 |
+
# ๋น๋๊ธฐ์ ์ผ๋ก ๊ต์ก ๊ณผ์ ์์ฑ
|
| 41 |
+
async def generate_curriculum(prompt):
|
| 42 |
+
model = create_model() # ์๋ก์ด ๋ชจ๋ธ ์ธ์คํด์ค ์์ฑ
|
| 43 |
+
|
| 44 |
prompt_parts = [
|
| 45 |
"Concept-Based Curriculum Expert, ๊ฐ๋
๊ธฐ๋ฐ๊ต์ก๊ณผ์ ์ค๊ณ ์ ๋ฌธ๊ฐ. ์ด๋ฑํ๊ต ๊ต์ก๊ณผ์ ๋ฒ์ ๋ด์์ ๊ฐ๋
๊ธฐ๋ฐ ๊ต์ก๊ณผ์ ๋ฐ ์์
์ ์ฒด๊ณ์ ์ผ๋ก ์ค๊ณ.",
|
| 46 |
"์ฑ์ทจ๊ธฐ์ค ์ฑ์ทจ ๊ธฐ์ค ๋ฐ ์์
๋ชฉํ",
|
|
|
|
| 57 |
for chunk in response:
|
| 58 |
full_text += chunk.text
|
| 59 |
yield full_text
|
| 60 |
+
await gr.sleep(0.05) # ๋น๋๊ธฐ์ ์ผ๋ก ์ง์ฐ ์ถ๊ฐ
|
| 61 |
except Exception as e:
|
| 62 |
yield f"์๋ฌ ๋ฐ์: {str(e)}"
|
| 63 |
|
| 64 |
+
# ์ธํฐํ์ด์ค ์ค์ (queue() ํจ์ ์ถ๊ฐ)
|
| 65 |
iface = gr.Interface(
|
| 66 |
fn=generate_curriculum,
|
| 67 |
inputs=gr.Textbox(lines=1, label="์ฑ์ทจ๊ธฐ์ค ์
๋ ฅ"),
|
|
|
|
| 70 |
description="์ฑ์ทจ๊ธฐ์ค์ ์
๋ ฅํ๋ฉด ๊ฐ๋
๊ธฐ๋ฐ ๊ต์ก๊ณผ์ ์ ์ค๊ณํฉ๋๋ค."
|
| 71 |
)
|
| 72 |
|
| 73 |
+
iface.queue().launch() # queue() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋๊ธฐ์ ์ผ๋ก ์คํ
|