ll7098ll commited on
Commit
7cc4897
ยท
verified ยท
1 Parent(s): 8d4e5b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -5,8 +5,8 @@ import time
5
 
6
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
 
8
- # ๋ชจ๋ธ ์„ค์ •์„ ํ•จ์ˆ˜ ๋‚ด๋ถ€๋กœ ์ด๋™
9
- def generate_curriculum(prompt):
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
- time.sleep(0.05) # ์•ฝ๊ฐ„์˜ ์ง€์—ฐ ์ถ”๊ฐ€
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() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์‹คํ–‰