JUNGU commited on
Commit
bca9727
·
1 Parent(s): 32170e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -21
app.py CHANGED
@@ -107,7 +107,47 @@ achievement_standard = st.text_input("성취기준 입력:", value=selected_stan
107
  # for sentence in st.session_state.similar_sentences:
108
  # st.write(sentence)
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  # 세션 상태 초기화
 
 
111
  if 'selected_sentence' not in st.session_state:
112
  st.session_state.selected_sentence = None
113
  if 'similar_sentences' not in st.session_state:
@@ -119,28 +159,24 @@ if st.button("평가 생성"):
119
  result = generate_annotated_text(achievement_standard)
120
  st.session_state.generated_result = result
121
  st.session_state.selected_sentence = None # 새로운 평가 생성시 선택된 문장 초기화
 
122
  exec(result.replace('```', ''))
123
 
 
 
124
  # annotated_text 결과에서 문장만 추출
125
- result_lines = result.split('\n')
126
- sentences = []
127
- for line in result_lines:
128
- start_idx = line.find('("')
129
- if start_idx != -1:
130
- end_idx = line.find('",', start_idx)
131
- sentence = line[start_idx + 2:end_idx].strip()
132
- sentences.append(sentence)
133
-
134
  if sentences:
135
- st.session_state.selected_sentence = st.selectbox("문장을 선택하세요:", sentences, key="sentence_select")
136
-
137
- # 유사한 문장 생성 버튼 추가
138
- if st.button("유사한 문구 생성") and st.session_state.get('selected_sentence'):
139
- with st.spinner('문장 생성중...'):
140
- st.session_state.similar_sentences = generate_similar_sentences(st.session_state.selected_sentence)
141
-
142
- # 생성된 결과 및 유사한 문장들 출력
143
- if st.session_state.get('generated_result'):
144
- exec(st.session_state.generated_result.replace('```', ''))
145
- for sentence in st.session_state.get('similar_sentences', []):
146
- st.write(sentence)
 
107
  # for sentence in st.session_state.similar_sentences:
108
  # st.write(sentence)
109
 
110
+ # # 세션 상태 초기화
111
+ # if 'selected_sentence' not in st.session_state:
112
+ # st.session_state.selected_sentence = None
113
+ # if 'similar_sentences' not in st.session_state:
114
+ # st.session_state.similar_sentences = []
115
+
116
+ # # "평가 생성" 버튼 클릭 시의 동작
117
+ # if st.button("평가 생성"):
118
+ # with st.spinner('답변 생성중...'):
119
+ # result = generate_annotated_text(achievement_standard)
120
+ # st.session_state.generated_result = result
121
+ # st.session_state.selected_sentence = None # 새로운 평가 생성시 선택된 문장 초기화
122
+ # exec(result.replace('```', ''))
123
+
124
+ # # annotated_text 결과에서 문장만 추출
125
+ # result_lines = result.split('\n')
126
+ # sentences = []
127
+ # for line in result_lines:
128
+ # start_idx = line.find('("')
129
+ # if start_idx != -1:
130
+ # end_idx = line.find('",', start_idx)
131
+ # sentence = line[start_idx + 2:end_idx].strip()
132
+ # sentences.append(sentence)
133
+
134
+ # if sentences:
135
+ # st.session_state.selected_sentence = st.selectbox("문장을 선택하세요:", sentences, key="sentence_select")
136
+
137
+ # # 유사한 문장 생성 버튼 추가
138
+ # if st.button("유사한 문구 생성") and st.session_state.get('selected_sentence'):
139
+ # with st.spinner('문장 생성중...'):
140
+ # st.session_state.similar_sentences = generate_similar_sentences(st.session_state.selected_sentence)
141
+
142
+ # # 생성된 결과 및 유사한 문장들 출력
143
+ # if st.session_state.get('generated_result'):
144
+ # exec(st.session_state.generated_result.replace('```', ''))
145
+ # for sentence in st.session_state.get('similar_sentences', []):
146
+ # st.write(sentence)
147
+
148
  # 세션 상태 초기화
149
+ if 'generated_result' not in st.session_state:
150
+ st.session_state.generated_result = None
151
  if 'selected_sentence' not in st.session_state:
152
  st.session_state.selected_sentence = None
153
  if 'similar_sentences' not in st.session_state:
 
159
  result = generate_annotated_text(achievement_standard)
160
  st.session_state.generated_result = result
161
  st.session_state.selected_sentence = None # 새로운 평가 생성시 선택된 문장 초기화
162
+ st.session_state.similar_sentences = [] # 이전 유사한 문장들 초기화
163
  exec(result.replace('```', ''))
164
 
165
+ # 셀렉트 박스 및 유사한 문장 생성 버튼 추가
166
+ if st.session_state.generated_result:
167
  # annotated_text 결과에서 문장만 추출
168
+ result_lines = st.session_state.generated_result.split('\n')
169
+ sentences = [line[start_idx + 2:line.find('",', start_idx)].strip() for line in result_lines if (start_idx := line.find('("')) != -1]
170
+
 
 
 
 
 
 
171
  if sentences:
172
+ selected_sentence = st.selectbox("문장을 선택하세요:", sentences, key="sentence_select")
173
+ st.session_state.selected_sentence = selected_sentence
174
+
175
+ # 유사한 문장 생성 버튼
176
+ if st.button("유사한 문구 생성") and st.session_state.selected_sentence:
177
+ with st.spinner('문장 생성중...'):
178
+ st.session_state.similar_sentences = generate_similar_sentences(st.session_state.selected_sentence)
179
+
180
+ # 유사한 문장들 출력
181
+ for sentence in st.session_state.similar_sentences:
182
+ st.write(sentence)