davidna22 commited on
Commit
6972fdf
·
1 Parent(s): faae14e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -9
app.py CHANGED
@@ -62,7 +62,7 @@ def init_app(api_key,
62
  dtype=dtype,
63
  device="cuda")
64
  return {
65
- progress_box: "### Current Progress \n Model Initialized Successfully! Time to Run the Simulation",
66
  log_output: console_logs.getvalue(),
67
  main_block_step_1: gr.update(visible=False),
68
  main_block_step_2: gr.update(visible=True),
@@ -70,6 +70,7 @@ def init_app(api_key,
70
  run_sim_btn: gr.update(visible=True)
71
  }
72
 
 
73
  def run_simulation(topic,
74
  save=True,
75
  num_responses=50,
@@ -121,15 +122,16 @@ def run_simulation(topic,
121
  subfolder = topic.replace(" ", "-")
122
  img_filename = f"{image_folder}/{subfolder}/tweet-img-row-0.png"
123
  img_fullpath = os.path.join(os.path.dirname(__file__), img_filename)
124
- sys.stdout=restore_point
125
  return {
126
- progress_box: "### Current Progress \n To see your results, visit the bot simulation Mastodon server. \n Link to Mastodon Server: [https://bot-simulation-research.app/home](https://bot-simulation-research.app/home)",
127
  log_output: console_logs.getvalue(),
128
  simulation_output_box: gr.update(visible=True),
129
  saved_file: tweet_filename,
130
  example_image: img_fullpath
131
  }
132
 
 
133
  def toggle_image_params(with_images):
134
  if with_images:
135
  return {
@@ -140,6 +142,7 @@ def toggle_image_params(with_images):
140
  image_params: gr.update(visible=False)
141
  }
142
 
 
143
  def add_token_func(add_token):
144
  image_tokens_list.append(add_token)
145
  return {
@@ -147,8 +150,27 @@ def add_token_func(add_token):
147
  }
148
 
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  with gr.Blocks() as demo:
151
  gr.HTML(title)
 
152
  with gr.Column(elem_id="main_block", visible=False) as main_block:
153
  with gr.Column(elem_id = "main_block_step_1", visible=True) as main_block_step_1:
154
  gr.HTML(value=subtitle_1)
@@ -194,7 +216,7 @@ with gr.Blocks() as demo:
194
  topic = gr.Textbox(label="Enter the topic to Generate tweets (Ex: \"The Earth is Flat\")")
195
  save = gr.Checkbox(label="Download Generated Tweets CSV? (Y/n)", value=True)
196
  with gr.Accordion("Additional Parameters", open=False):
197
- num_responses = gr.Slider(label= "Number of total fake Tweets to generate",minimum=20, maximum=500, step=5)
198
  n = gr.Slider(label="Number of Tweets to return per API call (smaller = More randomized answers)", value=10, minimum=1, maximum=50, step=1)
199
  system_prompt = gr.Dropdown(label="",
200
  value=BotSimulator.assistant_prompt,
@@ -272,7 +294,7 @@ with gr.Blocks() as demo:
272
 
273
  with gr.Row(elem_id="progress_box") as progress_box:
274
  with gr.Column():
275
- progress_box = gr.Markdown("### Current Progress <br>")
276
  with gr.Column():
277
  log_output = gr.Textbox(every=0.5, label="Logs", lines=8)
278
 
@@ -293,9 +315,10 @@ with gr.Blocks() as demo:
293
  augment_mode,
294
  image_every_n_posts,
295
  image_subtoken,
 
296
  news_company,
297
  text_model_name],
298
- outputs=[progress_box,
299
  log_output,
300
  simulation_output_box,
301
  saved_file,
@@ -311,16 +334,26 @@ with gr.Blocks() as demo:
311
  diffusion_model,
312
  keyword_model,
313
  dtype],
314
- outputs=[progress_box,
315
  log_output,
316
  main_block_step_1,
317
  main_block_step_2,
318
  init_btn,
319
  run_sim_btn])
320
-
321
  with gr.Row(elem_id="reset_block", visible=True) as reset_block:
322
  reset_btn = gr.Button("Reset")
323
- # reset_btn.click()
 
 
 
 
 
 
 
 
 
 
324
 
325
  with gr.Column(elem_id = "user_consent_container") as user_consent_block:
326
  accept_checkbox = gr.Checkbox(visible=False)
 
62
  dtype=dtype,
63
  device="cuda")
64
  return {
65
+ progress_output: "### Current Progress \n Model Initialized Successfully! Time to Run the Simulation",
66
  log_output: console_logs.getvalue(),
67
  main_block_step_1: gr.update(visible=False),
68
  main_block_step_2: gr.update(visible=True),
 
70
  run_sim_btn: gr.update(visible=True)
71
  }
72
 
73
+
74
  def run_simulation(topic,
75
  save=True,
76
  num_responses=50,
 
122
  subfolder = topic.replace(" ", "-")
123
  img_filename = f"{image_folder}/{subfolder}/tweet-img-row-0.png"
124
  img_fullpath = os.path.join(os.path.dirname(__file__), img_filename)
125
+ sys.stdout = restore_point
126
  return {
127
+ progress_output: "### Current Progress \n To see your results, visit the bot simulation Mastodon server. \n Link to Mastodon Server: [https://bot-simulation-research.app/home](https://bot-simulation-research.app/home)",
128
  log_output: console_logs.getvalue(),
129
  simulation_output_box: gr.update(visible=True),
130
  saved_file: tweet_filename,
131
  example_image: img_fullpath
132
  }
133
 
134
+
135
  def toggle_image_params(with_images):
136
  if with_images:
137
  return {
 
142
  image_params: gr.update(visible=False)
143
  }
144
 
145
+
146
  def add_token_func(add_token):
147
  image_tokens_list.append(add_token)
148
  return {
 
150
  }
151
 
152
 
153
+ def reset_app():
154
+ sys.stdout = restore_point
155
+ console_logs = StringIO()
156
+ return {
157
+ progress_output: gr.update(value="### Current Progress <br>"),
158
+ log_output: console_logs.getvalue(),
159
+ api_key: gr.update(value=""),
160
+ topic: gr.update(value=""),
161
+ with_images: gr.update(value=False),
162
+ image_params: gr.update(visible=False),
163
+ main_block_step_1: gr.update(visible=True),
164
+ main_block_step_2: gr.update(visible=False),
165
+ simulation_output_box: gr.update(visible=False),
166
+ run_sim_btn: gr.update(visible=False),
167
+ init_btn: gr.update(visible=True)
168
+ }
169
+
170
+
171
  with gr.Blocks() as demo:
172
  gr.HTML(title)
173
+ demo_state = gr.State("Terms")
174
  with gr.Column(elem_id="main_block", visible=False) as main_block:
175
  with gr.Column(elem_id = "main_block_step_1", visible=True) as main_block_step_1:
176
  gr.HTML(value=subtitle_1)
 
216
  topic = gr.Textbox(label="Enter the topic to Generate tweets (Ex: \"The Earth is Flat\")")
217
  save = gr.Checkbox(label="Download Generated Tweets CSV? (Y/n)", value=True)
218
  with gr.Accordion("Additional Parameters", open=False):
219
+ num_responses = gr.Slider(label= "Number of total fake Tweets to generate", value=20, minimum=20, maximum=500, step=5)
220
  n = gr.Slider(label="Number of Tweets to return per API call (smaller = More randomized answers)", value=10, minimum=1, maximum=50, step=1)
221
  system_prompt = gr.Dropdown(label="",
222
  value=BotSimulator.assistant_prompt,
 
294
 
295
  with gr.Row(elem_id="progress_box") as progress_box:
296
  with gr.Column():
297
+ progress_output = gr.Markdown("### Current Progress <br>")
298
  with gr.Column():
299
  log_output = gr.Textbox(every=0.5, label="Logs", lines=8)
300
 
 
315
  augment_mode,
316
  image_every_n_posts,
317
  image_subtoken,
318
+ image_tokens,
319
  news_company,
320
  text_model_name],
321
+ outputs=[progress_output,
322
  log_output,
323
  simulation_output_box,
324
  saved_file,
 
334
  diffusion_model,
335
  keyword_model,
336
  dtype],
337
+ outputs=[progress_output,
338
  log_output,
339
  main_block_step_1,
340
  main_block_step_2,
341
  init_btn,
342
  run_sim_btn])
343
+
344
  with gr.Row(elem_id="reset_block", visible=True) as reset_block:
345
  reset_btn = gr.Button("Reset")
346
+ reset_btn.click(reset_app, inputs=[], outputs=[progress_output,
347
+ log_output,
348
+ api_key,
349
+ topic,
350
+ with_images,
351
+ image_params,
352
+ main_block_step_1,
353
+ main_block_step_2,
354
+ simulation_output_box,
355
+ run_sim_btn,
356
+ init_btn])
357
 
358
  with gr.Column(elem_id = "user_consent_container") as user_consent_block:
359
  accept_checkbox = gr.Checkbox(visible=False)