ll7098ll commited on
Commit
1be716f
·
verified ·
1 Parent(s): 7869553

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -50,7 +50,40 @@ st.markdown(
50
 
51
 
52
  def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic):
53
- # ... (생략) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
 
56
  # Streamlit 인터페이스 설정
 
50
 
51
 
52
  def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic):
53
+ generation_config = {
54
+ "temperature": 0.3,
55
+ "top_p": 0.95,
56
+ "top_k": 64,
57
+ "max_output_tokens": 15000, # 맥스 토큰 설정 추가
58
+ "response_mime_type": "text/plain",
59
+ }
60
+
61
+ model = genai.GenerativeModel(
62
+ model_name="gemini-1.5-pro-exp-0827",
63
+ generation_config=generation_config,
64
+ )
65
+
66
+ # 프롬프트 생성
67
+ prompt = f"""
68
+ 초등학교 {grade}학년 학생이 이해할 수 있는 수준의 설명문을 작성.
69
+ 설명문의 주제는 {topic}이며, 주제를 중심으로 {structure} 구조에 따라 설명문을 작성할 것,
70
+ 전체 문단 수는 {num_paragraphs} 문단 내외, 문단 당 문장 수는 {sentences_per_paragraph} 문장 내외,
71
+ 설명문은 줄글로 작성하고 문단 구분을 꼭 할 것, 지정된 문단 수와 문단 당 문장 수를 꼭 지킬것.
72
+ """
73
+
74
+ full_text = ""
75
+ text_area = st.empty() # 텍스트 출력을 위한 빈 텍스트 에어리어 생성
76
+
77
+ try:
78
+ # 스트리밍 방식으로 응답 생성
79
+ response = model.generate_content(prompt, stream=True)
80
+ for chunk in response:
81
+ full_text += chunk.text
82
+ text_area.text_area("읽기 자료", value=full_text, height=300) # 텍스트 에어리어 높이 조정
83
+ time.sleep(0.05)
84
+
85
+ except Exception as e:
86
+ st.error(f"에러 발생: {str(e)}")
87
 
88
 
89
  # Streamlit 인터페이스 설정