ll7098ll commited on
Commit
8d4e5b9
ยท
verified ยท
1 Parent(s): 6c32ea0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -22
app.py CHANGED
@@ -5,40 +5,39 @@ import time
5
 
6
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
 
8
- # ๋ชจ๋ธ ์„ค์ •์„ ํ•จ์ˆ˜ ์™ธ๋ถ€๋กœ ์ด๋™
9
- generation_config = {
 
10
  "temperature": 1,
11
  "top_p": 0.95,
12
  "top_k": 64,
13
  "max_output_tokens": 15000,
14
- }
15
 
16
- safety_settings = [
17
  {
18
- "category": "HARM_CATEGORY_HARASSMENT",
19
- "threshold": "BLOCK_NONE"
20
  },
21
  {
22
- "category": "HARM_CATEGORY_HATE_SPEECH",
23
- "threshold": "BLOCK_NONE"
24
  },
25
  {
26
- "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
27
- "threshold": "BLOCK_NONE"
28
  },
29
  {
30
- "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
31
- "threshold": "BLOCK_NONE"
32
  },
33
- ]
34
-
35
- # ๋ชจ๋ธ์„ ๋ฏธ๋ฆฌ ์ƒ์„ฑ
36
- model = genai.GenerativeModel(model_name="gemini-1.5-pro",
37
- generation_config=generation_config,
38
- safety_settings=safety_settings)
39
 
 
 
 
 
40
 
41
- def generate_curriculum(prompt, full_text):
42
  prompt_parts = [
43
  "Concept-Based Curriculum Expert, ๊ฐœ๋…๊ธฐ๋ฐ˜๊ต์œก๊ณผ์ • ์„ค๊ณ„ ์ „๋ฌธ๊ฐ€. ์ดˆ๋“ฑํ•™๊ต ๊ต์œก๊ณผ์ • ๋ฒ”์œ„ ๋‚ด์—์„œ ๊ฐœ๋…๊ธฐ๋ฐ˜ ๊ต์œก๊ณผ์ • ๋ฐ ์ˆ˜์—…์„ ์ฒด๊ณ„์ ์œผ๋กœ ์„ค๊ณ„.",
44
  "์„ฑ์ทจ๊ธฐ์ค€ ์„ฑ์ทจ ๊ธฐ์ค€ ๋ฐ ์ˆ˜์—… ๋ชฉํ‘œ",
@@ -47,16 +46,19 @@ def generate_curriculum(prompt, full_text):
47
  "๊ฐœ๋…๊ธฐ๋ฐ˜ ๊ต์œก๊ณผ์ • ",
48
  ]
49
 
 
 
 
50
  try:
51
  response = model.generate_content(prompt_parts, stream=True)
52
  for chunk in response:
53
  full_text += chunk.text
54
- time.sleep(0.05)
55
- yield full_text # ํ˜„์žฌ๊นŒ์ง€ ์ƒ์„ฑ๋œ ํ…์ŠคํŠธ ์ถœ๋ ฅ
56
  except Exception as e:
57
  yield f"์—๋Ÿฌ ๋ฐœ์ƒ: {str(e)}"
58
 
59
- # ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
60
  iface = gr.Interface(
61
  fn=generate_curriculum,
62
  inputs=gr.Textbox(lines=1, label="์„ฑ์ทจ๊ธฐ์ค€ ์ž…๋ ฅ"),
 
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,
13
  "top_k": 64,
14
  "max_output_tokens": 15000,
15
+ }
16
 
17
+ safety_settings = [
18
  {
19
+ "category": "HARM_CATEGORY_HARASSMENT",
20
+ "threshold": "BLOCK_NONE"
21
  },
22
  {
23
+ "category": "HARM_CATEGORY_HATE_SPEECH",
24
+ "threshold": "BLOCK_NONE"
25
  },
26
  {
27
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
28
+ "threshold": "BLOCK_NONE"
29
  },
30
  {
31
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
32
+ "threshold": "BLOCK_NONE"
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
  "์„ฑ์ทจ๊ธฐ์ค€ ์„ฑ์ทจ ๊ธฐ์ค€ ๋ฐ ์ˆ˜์—… ๋ชฉํ‘œ",
 
46
  "๊ฐœ๋…๊ธฐ๋ฐ˜ ๊ต์œก๊ณผ์ • ",
47
  ]
48
 
49
+ full_text = ""
50
+ yield full_text # ์ดˆ๊ธฐ ๋นˆ ํ…์ŠคํŠธ ์ถœ๋ ฅ
51
+
52
  try:
53
  response = model.generate_content(prompt_parts, stream=True)
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="์„ฑ์ทจ๊ธฐ์ค€ ์ž…๋ ฅ"),