yaleh commited on
Commit
e461e3a
·
1 Parent(s): dea4a7a

Replace the input text area with an editable table.

Browse files
Files changed (1) hide show
  1. app/streamlit_sample_generator.py +58 -31
app/streamlit_sample_generator.py CHANGED
@@ -127,6 +127,9 @@ def example_selected():
127
 
128
 
129
  # Session State
 
 
 
130
  if 'description_output_text' not in st.session_state:
131
  st.session_state.description_output_text = ''
132
 
@@ -153,6 +156,7 @@ if 'selected_example' not in st.session_state:
153
 
154
 
155
  def update_description_output_text():
 
156
  st.session_state.description_output_text = generate_description_only(
157
  input_json, model_name, temperature)
158
 
@@ -168,6 +172,7 @@ def update_example_briefs_output_text():
168
 
169
 
170
  def update_examples_from_briefs_dataframe():
 
171
  examples = generate_examples_from_briefs(
172
  description_output, example_briefs_output, input_json, generating_batch_size, model_name, temperature)
173
  st.session_state.examples_from_briefs_dataframe = pd.DataFrame(
@@ -175,6 +180,7 @@ def update_examples_from_briefs_dataframe():
175
 
176
 
177
  def update_examples_directly_dataframe():
 
178
  examples = generate_examples_directly(
179
  description_output, input_json, generating_batch_size, model_name, temperature)
180
  st.session_state.examples_directly_dataframe = pd.DataFrame(
@@ -182,6 +188,7 @@ def update_examples_directly_dataframe():
182
 
183
 
184
  def generate_examples_dataframe():
 
185
  result = process_json(input_json, model_name,
186
  generating_batch_size, temperature)
187
  description, examples_directly, input_analysis, new_example_briefs, examples_from_briefs, examples = result
@@ -196,13 +203,30 @@ def generate_examples_dataframe():
196
  examples, columns=["Input", "Output"])
197
  st.session_state.selected_example = None
198
 
 
 
 
 
 
199
 
200
  # Streamlit UI
201
  st.title("Task Description Generator")
202
  st.markdown("Enter a JSON object with 'input' and 'output' fields to generate a task description and additional examples.")
203
 
204
  # Input column
205
- input_json = st.text_area("Input JSON", height=200)
 
 
 
 
 
 
 
 
 
 
 
 
206
  model_name = st.selectbox(
207
  "Model Name",
208
  ["llama3-70b-8192", "llama3-8b-8192", "llama-3.1-70b-versatile",
@@ -252,33 +276,36 @@ new_example_json = st.text_area(
252
  "New Example JSON", value=st.session_state.selected_example, height=100)
253
 
254
  # Button actions
255
- if submit_button:
256
- try:
257
- result = process_json(
258
- input_json, model_name, generating_batch_size, temperature
259
- )
260
- description, examples_directly, input_analysis, new_example_briefs, examples_from_briefs, examples = result
261
- description_output = description
262
- examples_directly_output = examples_directly
263
- input_analysis_output = input_analysis
264
- example_briefs_output = new_example_briefs
265
- examples_from_briefs_output = examples_from_briefs
266
- examples_output = examples
267
- except Exception as e:
268
- st.error(f"An error occurred: {str(e)}")
269
-
270
- if generate_examples_directly_button:
271
- examples_directly_output = generate_examples_directly(
272
- description_output, input_json, generating_batch_size, model_name, temperature)
273
-
274
- if analyze_input_button:
275
- input_analysis_output = analyze_input(
276
- description_output, model_name, temperature)
277
-
278
- if generate_briefs_button:
279
- example_briefs_output = generate_briefs(
280
- description_output, input_analysis_output, generating_batch_size, model_name, temperature)
281
-
282
- if generate_examples_from_briefs_button:
283
- examples_from_briefs_output = generate_examples_from_briefs(
284
- description_output, example_briefs_output, input_json, generating_batch_size, model_name, temperature)
 
 
 
 
127
 
128
 
129
  # Session State
130
+ if 'input_data' not in st.session_state:
131
+ st.session_state.input_data = pd.DataFrame(columns=["Input", "Output"])
132
+
133
  if 'description_output_text' not in st.session_state:
134
  st.session_state.description_output_text = ''
135
 
 
156
 
157
 
158
  def update_description_output_text():
159
+ input_json = package_input_data()
160
  st.session_state.description_output_text = generate_description_only(
161
  input_json, model_name, temperature)
162
 
 
172
 
173
 
174
  def update_examples_from_briefs_dataframe():
175
+ input_json = package_input_data()
176
  examples = generate_examples_from_briefs(
177
  description_output, example_briefs_output, input_json, generating_batch_size, model_name, temperature)
178
  st.session_state.examples_from_briefs_dataframe = pd.DataFrame(
 
180
 
181
 
182
  def update_examples_directly_dataframe():
183
+ input_json = package_input_data()
184
  examples = generate_examples_directly(
185
  description_output, input_json, generating_batch_size, model_name, temperature)
186
  st.session_state.examples_directly_dataframe = pd.DataFrame(
 
188
 
189
 
190
  def generate_examples_dataframe():
191
+ input_json = package_input_data()
192
  result = process_json(input_json, model_name,
193
  generating_batch_size, temperature)
194
  description, examples_directly, input_analysis, new_example_briefs, examples_from_briefs, examples = result
 
203
  examples, columns=["Input", "Output"])
204
  st.session_state.selected_example = None
205
 
206
+ def package_input_data():
207
+ data = input_data.to_dict(orient='records')
208
+ lowered_data = [{k.lower(): v for k, v in d.items()} for d in data]
209
+ return json.dumps(lowered_data, ensure_ascii=False)
210
+
211
 
212
  # Streamlit UI
213
  st.title("Task Description Generator")
214
  st.markdown("Enter a JSON object with 'input' and 'output' fields to generate a task description and additional examples.")
215
 
216
  # Input column
217
+ input_data = st.data_editor(
218
+ st.session_state.input_data,
219
+ num_rows="dynamic",
220
+ use_container_width=True,
221
+ column_config={
222
+ "Input": st.column_config.TextColumn("Input", width="large"),
223
+ "Output": st.column_config.TextColumn("Output", width="large"),
224
+ },
225
+ )
226
+
227
+ # # Update session state
228
+ # st.session_state.input_data = input_data
229
+
230
  model_name = st.selectbox(
231
  "Model Name",
232
  ["llama3-70b-8192", "llama3-8b-8192", "llama-3.1-70b-versatile",
 
276
  "New Example JSON", value=st.session_state.selected_example, height=100)
277
 
278
  # Button actions
279
+ # if submit_button:
280
+ # try:
281
+ # input_json = package_input_data()
282
+ # result = process_json(
283
+ # input_json, model_name, generating_batch_size, temperature
284
+ # )
285
+ # description, examples_directly, input_analysis, new_example_briefs, examples_from_briefs, examples = result
286
+ # description_output = description
287
+ # examples_directly_output = examples_directly
288
+ # input_analysis_output = input_analysis
289
+ # example_briefs_output = new_example_briefs
290
+ # examples_from_briefs_output = examples_from_briefs
291
+ # examples_output = examples
292
+ # except Exception as e:
293
+ # st.error(f"An error occurred: {str(e)}")
294
+
295
+ # if generate_examples_directly_button:
296
+ # input_json = package_input_data()
297
+ # examples_directly_output = generate_examples_directly(
298
+ # description_output, input_json, generating_batch_size, model_name, temperature)
299
+
300
+ # if analyze_input_button:
301
+ # input_analysis_output = analyze_input(
302
+ # description_output, model_name, temperature)
303
+
304
+ # if generate_briefs_button:
305
+ # example_briefs_output = generate_briefs(
306
+ # description_output, input_analysis_output, generating_batch_size, model_name, temperature)
307
+
308
+ # if generate_examples_from_briefs_button:
309
+ # input_json = package_input_data()
310
+ # examples_from_briefs_output = generate_examples_from_briefs(
311
+ # description_output, example_briefs_output, input_json, generating_batch_size, model_name, temperature)