ll7098ll commited on
Commit
dc6c650
ยท
verified ยท
1 Parent(s): feb03cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
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
- for chunk in response:
55
- full_text += chunk.text
56
- yield full_text
 
 
 
 
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,