davidna22 commited on
Commit
f7d951f
·
1 Parent(s): 5c9916f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -3,12 +3,13 @@ import sys
3
  import subprocess
4
  import os
5
  sys.path.append("./")
 
6
  import BotSimulator
7
  from BotSimulator import TootBot
8
  import openai
9
  from io import StringIO
10
  import multiprocessing
11
- restore_point = sys.stdout
12
 
13
 
14
  if not os.path.exists("data/fake-tweets"):
@@ -25,6 +26,7 @@ subtitle_2 = """<h2 align="center">Run bot simulation</h2>"""
25
  image_tokens_list = ["black and white", "year 2023", "cartoon", "animated",
26
  "comic", "propaganda", "news", "classic disney style",
27
  "holliemengert artstyle"]
 
28
  pool = multiprocessing.Pool()
29
  num_processes = pool._processes
30
  global tootbot_app
@@ -36,7 +38,8 @@ def init_app(api_key,
36
  temperature,
37
  diffusion_model,
38
  keyword_model,
39
- dtype):
 
40
 
41
  try:
42
  openai.api_key = api_key
@@ -46,7 +49,7 @@ def init_app(api_key,
46
 
47
  console_logs = StringIO()
48
  sys.stdout = console_logs
49
- model_class = model_class.replace(" ","").lower()
50
  global tootbot_app
51
  tootbot_app = TootBot(model=model_name,
52
  model_class=model_class,
@@ -63,7 +66,8 @@ def init_app(api_key,
63
  os.remove("client_cred.secret")
64
  os.environ["OPENAI_API_KEY"] = api_key
65
  os.environ["OPENAI_API_KEY_2"] = api_key
66
- tootbot_app.init_models(diffusion_model=diffusion_model,
 
67
  keyword_model=keyword_model,
68
  text_fail_classifier="davidna22/text-failed-classifier",
69
  dtype=dtype,
@@ -93,7 +97,7 @@ def run_simulation(topic,
93
  text_model_name="gpt-3.5-turbo-0301"):
94
  if topic == "":
95
  raise gr.Error("Topic must not be empty")
96
-
97
  console_logs = StringIO()
98
  sys.stdout = console_logs
99
  filename = topic.replace(" ", "-") + ".csv"
@@ -168,6 +172,7 @@ def reset_app():
168
  log_output: console_logs.getvalue(),
169
  api_key: gr.update(value=""),
170
  topic: gr.update(value=""),
 
171
  with_images: gr.update(value=False),
172
  image_params: gr.update(visible=False),
173
  main_block_step_1: gr.update(visible=True),
@@ -182,7 +187,7 @@ with gr.Blocks() as demo:
182
  gr.HTML(title)
183
  demo_state = gr.State("Terms")
184
  with gr.Column(elem_id="main_block", visible=False) as main_block:
185
- with gr.Column(elem_id = "main_block_step_1", visible=True) as main_block_step_1:
186
  gr.HTML(value=subtitle_1)
187
  api_key = gr.Textbox(label="Enter your API key")
188
  model_class = gr.Dropdown(value="Open AI",
@@ -199,6 +204,8 @@ with gr.Blocks() as demo:
199
  "gpt-4-32k-0314"])
200
  temperature = gr.Number(label="Set Your Temperature (0.0-2.0)", value=0.9)
201
  with gr.Accordion("Additional Parameters", open=False):
 
 
202
  diffusion_model = gr.Dropdown(value="stabilityai/stable-diffusion-2-1-base",
203
  choices=["stabilityai/stable-diffusion-2-1-base",
204
  "stabilityai/stable-diffusion-2-base",
@@ -343,7 +350,8 @@ with gr.Blocks() as demo:
343
  temperature,
344
  diffusion_model,
345
  keyword_model,
346
- dtype],
 
347
  outputs=[progress_output,
348
  log_output,
349
  main_block_step_1,
@@ -357,6 +365,7 @@ with gr.Blocks() as demo:
357
  log_output,
358
  api_key,
359
  topic,
 
360
  with_images,
361
  image_params,
362
  main_block_step_1,
@@ -390,4 +399,4 @@ with gr.Blocks() as demo:
390
  accept_checkbox.change(fn=enable_inputs, inputs=[], outputs=[user_consent_block, main_block], queue=False)
391
 
392
  demo.queue(concurrency_count=num_processes)
393
- demo.launch(share=False)
 
3
  import subprocess
4
  import os
5
  sys.path.append("./")
6
+ sys.path.append("../")
7
  import BotSimulator
8
  from BotSimulator import TootBot
9
  import openai
10
  from io import StringIO
11
  import multiprocessing
12
+ restore_point=sys.stdout
13
 
14
 
15
  if not os.path.exists("data/fake-tweets"):
 
26
  image_tokens_list = ["black and white", "year 2023", "cartoon", "animated",
27
  "comic", "propaganda", "news", "classic disney style",
28
  "holliemengert artstyle"]
29
+ topic_prompt_default = "Write a short tweet with less than 500 characters as if you were a real person with social media lingo and hashtags on this topic: "
30
  pool = multiprocessing.Pool()
31
  num_processes = pool._processes
32
  global tootbot_app
 
38
  temperature,
39
  diffusion_model,
40
  keyword_model,
41
+ dtype,
42
+ topic_prompt):
43
 
44
  try:
45
  openai.api_key = api_key
 
49
 
50
  console_logs = StringIO()
51
  sys.stdout = console_logs
52
+ model_class = model_class.replace(" ", "").lower()
53
  global tootbot_app
54
  tootbot_app = TootBot(model=model_name,
55
  model_class=model_class,
 
66
  os.remove("client_cred.secret")
67
  os.environ["OPENAI_API_KEY"] = api_key
68
  os.environ["OPENAI_API_KEY_2"] = api_key
69
+ tootbot_app.topic_prescript = topic_prompt.strip() + " "
70
+ tootbot_app.init_models(diffusion_model=diffusion_model,
71
  keyword_model=keyword_model,
72
  text_fail_classifier="davidna22/text-failed-classifier",
73
  dtype=dtype,
 
97
  text_model_name="gpt-3.5-turbo-0301"):
98
  if topic == "":
99
  raise gr.Error("Topic must not be empty")
100
+
101
  console_logs = StringIO()
102
  sys.stdout = console_logs
103
  filename = topic.replace(" ", "-") + ".csv"
 
172
  log_output: console_logs.getvalue(),
173
  api_key: gr.update(value=""),
174
  topic: gr.update(value=""),
175
+ topic_prompt: gr.update(value=topic_prompt_default),
176
  with_images: gr.update(value=False),
177
  image_params: gr.update(visible=False),
178
  main_block_step_1: gr.update(visible=True),
 
187
  gr.HTML(title)
188
  demo_state = gr.State("Terms")
189
  with gr.Column(elem_id="main_block", visible=False) as main_block:
190
+ with gr.Column(elem_id="main_block_step_1", visible=True) as main_block_step_1:
191
  gr.HTML(value=subtitle_1)
192
  api_key = gr.Textbox(label="Enter your API key")
193
  model_class = gr.Dropdown(value="Open AI",
 
204
  "gpt-4-32k-0314"])
205
  temperature = gr.Number(label="Set Your Temperature (0.0-2.0)", value=0.9)
206
  with gr.Accordion("Additional Parameters", open=False):
207
+ topic_prompt = gr.Textbox(label="Enter the Topic Prompt (Default Example below):",
208
+ value=topic_prompt_default)
209
  diffusion_model = gr.Dropdown(value="stabilityai/stable-diffusion-2-1-base",
210
  choices=["stabilityai/stable-diffusion-2-1-base",
211
  "stabilityai/stable-diffusion-2-base",
 
350
  temperature,
351
  diffusion_model,
352
  keyword_model,
353
+ dtype,
354
+ topic_prompt],
355
  outputs=[progress_output,
356
  log_output,
357
  main_block_step_1,
 
365
  log_output,
366
  api_key,
367
  topic,
368
+ topic_prompt,
369
  with_images,
370
  image_params,
371
  main_block_step_1,
 
399
  accept_checkbox.change(fn=enable_inputs, inputs=[], outputs=[user_consent_block, main_block], queue=False)
400
 
401
  demo.queue(concurrency_count=num_processes)
402
+ demo.launch(share=True)