ll7098ll commited on
Commit
3d3c68d
·
verified ·
1 Parent(s): 38259dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -63
app.py CHANGED
@@ -1,78 +1,38 @@
1
  import os
2
  import time
3
-
4
  import google.generativeai as genai
5
  import streamlit as st
 
 
 
 
6
 
7
  # Google Gemini API 설정
8
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
9
 
10
- # 스타일 설정
11
- st.markdown(
12
- """
13
- <style>
14
- .stApp {
15
- background-color: #f5f5f5;
16
- }
17
- .stTextInput>div>div>textarea {
18
- font-size: 16px;
19
- padding: 10px;
20
- border-radius: 5px;
21
- }
22
- .stButton>button {
23
- background-color: #007bff;
24
- color: white;
25
- padding: 10px 20px;
26
- border: none;
27
- border-radius: 5px;
28
- cursor: pointer;
29
- }
30
- .stSelectbox>div>div>select {
31
- font-size: 16px;
32
- padding: 5px;
33
- border-radius: 5px;
34
- }
35
- .stNumberInput>div>div>input {
36
- font-size: 16px;
37
- padding: 5px;
38
- border-radius: 5px;
39
- }
40
- .reportview-container .main .block-container {
41
- padding: 2rem 3rem;
42
- }
43
- .stTitle { /* 타이틀 스타일 조정 */
44
- font-size: 1.5rem; /* 원하는 크기로 조정 */
45
- font-weight: bold;
46
- }
47
- </style>
48
- """,
49
- unsafe_allow_html=True,
50
  )
51
 
52
-
53
  def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic):
54
- generation_config = {
55
- "temperature": 0.7,
56
- "top_p": 0.85,
57
- "top_k": 40,
58
- "max_output_tokens": 15000,
59
- "response_mime_type": "text/plain",
60
- }
61
-
62
- model = genai.GenerativeModel(
63
- model_name="gemini-1.5-pro-002",
64
- generation_config=generation_config,
65
- )
66
-
67
  prompt = f"""
68
  초등학교 {grade}학년 학생이 이해할 수 있는 수준의 설명문을 작성.
69
  설명문의 주제는 {topic}이며, 주제를 중심으로 {structure} 구조에 따라 설명문을 작성할 것.
70
  전체 문단 수는 {num_paragraphs} 문단 내외, 문단 당 문장 수는 {sentences_per_paragraph} 문장 내외.
71
  설명문은 줄글로 작성하고 문단 구분을 꼭 할 것. 지정된 문단 수와 문단 당 문장 수를 꼭 지킬 것.
72
  문단마다, 문단의 첫 문장 또는 마지막 문장이 문단의 중심 문장이 되도록 할 것. (중심 문장이란 문단의 내용을 모두 포함할 수 있는 문장)
73
-
74
  초등학교 {grade}학년 수준에 어려운 단어와 한자어, 학습 도구어는 마지막에 어휘 목록과 어휘의 뜻을 초등학교 {grade}학년 수준에 맞게 유의어나 뜻을 풀어 설명하는 부분 따로 추가할 것.
75
- """
76
 
77
  full_text = ""
78
  text_area = st.empty()
@@ -87,13 +47,17 @@ def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, top
87
  except Exception as e:
88
  st.error(f"에러 발생: {str(e)}")
89
 
90
-
91
  # Streamlit 인터페이스 설정
92
- st.title("📖 초등학생을 위한 읽기 자료 생성기 📖") # 타이틀 유지, 스타일은 CSS로 조정
93
- st.write("주제를 입력하면 초등학생이 이해하기 쉬운 읽기 자료를 만들어줍니다.")
 
 
 
 
 
94
 
95
  with st.sidebar:
96
- st.header("⚙️ 옵션 설정 ⚙️")
97
  grade = st.selectbox("학년", [str(i) for i in range(1, 7)], index=0)
98
  num_paragraphs = st.number_input("문단 수", min_value=1, value=3)
99
  sentences_per_paragraph = st.selectbox("문단 당 문장 수", ["3-4", "5-6", "6-7", "7-8", "9-10"], index=0)
@@ -101,5 +65,14 @@ with st.sidebar:
101
  topic = st.text_area("✏️ 주제 및 내용을 입력하세요 ", height=200)
102
 
103
 
104
- if st.button("읽기 자료 생성"):
105
- generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic)
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import time
 
3
  import google.generativeai as genai
4
  import streamlit as st
5
+ from streamlit_extras.colored_header import colored_header
6
+ from streamlit_extras.add_vertical_space import add_vertical_space
7
+ import markdown
8
+ import pyperclip
9
 
10
  # Google Gemini API 설정
11
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
12
 
13
+ # 모델 설정
14
+ generation_config = {
15
+ "temperature": 0.7,
16
+ "top_p": 0.85,
17
+ "top_k": 40,
18
+ "max_output_tokens": 15000,
19
+ "response_mime_type": "text/plain",
20
+ }
21
+
22
+ model = genai.GenerativeModel(
23
+ model_name="gemini-1.5-pro-002",
24
+ generation_config=generation_config,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  )
26
 
 
27
  def generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic):
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  prompt = f"""
29
  초등학교 {grade}학년 학생이 이해할 수 있는 수준의 설명문을 작성.
30
  설명문의 주제는 {topic}이며, 주제를 중심으로 {structure} 구조에 따라 설명문을 작성할 것.
31
  전체 문단 수는 {num_paragraphs} 문단 내외, 문단 당 문장 수는 {sentences_per_paragraph} 문장 내외.
32
  설명문은 줄글로 작성하고 문단 구분을 꼭 할 것. 지정된 문단 수와 문단 당 문장 수를 꼭 지킬 것.
33
  문단마다, 문단의 첫 문장 또는 마지막 문장이 문단의 중심 문장이 되도록 할 것. (중심 문장이란 문단의 내용을 모두 포함할 수 있는 문장)
 
34
  초등학교 {grade}학년 수준에 어려운 단어와 한자어, 학습 도구어는 마지막에 어휘 목록과 어휘의 뜻을 초등학교 {grade}학년 수준에 맞게 유의어나 뜻을 풀어 설명하는 부분 따로 추가할 것.
35
+ """
36
 
37
  full_text = ""
38
  text_area = st.empty()
 
47
  except Exception as e:
48
  st.error(f"에러 발생: {str(e)}")
49
 
 
50
  # Streamlit 인터페이스 설정
51
+ colored_header(
52
+ label="📖 초등학생을 위한 읽기 자료 생성기",
53
+ description="주제를 입력하면 초등학생이 이해하기 쉬운 읽기 자료를 만들어줍니다.",
54
+ color_name="purple-70",
55
+ )
56
+
57
+ add_vertical_space(1)
58
 
59
  with st.sidebar:
60
+ st.header("옵션 설정")
61
  grade = st.selectbox("학년", [str(i) for i in range(1, 7)], index=0)
62
  num_paragraphs = st.number_input("문단 수", min_value=1, value=3)
63
  sentences_per_paragraph = st.selectbox("문단 당 문장 수", ["3-4", "5-6", "6-7", "7-8", "9-10"], index=0)
 
65
  topic = st.text_area("✏️ 주제 및 내용을 입력하세요 ", height=200)
66
 
67
 
68
+ if st.button("읽기 자료 생성"):
69
+ generate_text(grade, num_paragraphs, sentences_per_paragraph, structure, topic)
70
+
71
+ # 복사 버튼 추가 (이미 생성된 경우)
72
+ if "generated_curriculum" in st.session_state and st.session_state.generated_curriculum:
73
+ html_text = markdown.markdown(st.session_state.generated_curriculum, extensions=['tables'])
74
+ st.markdown(html_text, unsafe_allow_html=True)
75
+
76
+ if st.button("출력 내용 복사", key="copy_button"):
77
+ pyperclip.copy(st.session_state.generated_curriculum)
78
+ st.success("복사되었습니다!")