Spaces:
Sleeping
Sleeping
Update BotSimulator.py
Browse files- BotSimulator.py +1 -98
BotSimulator.py
CHANGED
|
@@ -1335,101 +1335,4 @@ class TootBot:
|
|
| 1335 |
"""
|
| 1336 |
model_id = model_id
|
| 1337 |
self.keyword_model = KeyphraseExtractionPipeline(model=model_id)
|
| 1338 |
-
print(f"Keyword Extractor model {model_id} initialized")
|
| 1339 |
-
|
| 1340 |
-
|
| 1341 |
-
if __name__ == '__main__':
|
| 1342 |
-
print("------------------------------------------------------------------")
|
| 1343 |
-
print("Initializing Bot Simulation Application...")
|
| 1344 |
-
print("------------------------------------------------------------------")
|
| 1345 |
-
# model_class = input("Enter Model Class (Only supports \"openai\" as of 03/20/2023): ")
|
| 1346 |
-
# if model_class == "":
|
| 1347 |
-
# model_class = "openai"
|
| 1348 |
-
# model = input("Enter Model Name (default: \"gpt-3.5-turbo-0301\"): ")
|
| 1349 |
-
# if model == "":
|
| 1350 |
-
# model = "gpt-3.5-turbo-0301"
|
| 1351 |
-
# temperature = float(input("Enter Model Temperature (determinism parameter: 0.0-1.0): "))
|
| 1352 |
-
model_class = "openai"
|
| 1353 |
-
model = "gpt-3.5-turbo-0301"
|
| 1354 |
-
temperature = 0.9
|
| 1355 |
-
Tootbot = TootBot(model=model, model_class=model_class, temperature=temperature)
|
| 1356 |
-
|
| 1357 |
-
print("------------------------------------------------------------------")
|
| 1358 |
-
print("Initializing Mastodon Credentials...")
|
| 1359 |
-
print("------------------------------------------------------------------")
|
| 1360 |
-
# username = input("Enter your Mastodon username: ")
|
| 1361 |
-
# password = input("Enter your Mastodon password: ")
|
| 1362 |
-
# redirect_uri = input("Enter your redirect_uri (if not known, use default. Click enter): ")
|
| 1363 |
-
# if redirect_uri == "":
|
| 1364 |
-
# redirect_uri = "http://localhost:8080"
|
| 1365 |
-
# code= "<AUTHORIZATION_CODE>"
|
| 1366 |
-
username="[email protected]"
|
| 1367 |
-
password="DavidSamYungjun"
|
| 1368 |
-
redirect_uri="http://localhost:8080"
|
| 1369 |
-
client_id="mastodon/clientcred.secret"
|
| 1370 |
-
to_file="mastodon/usercred.secret"
|
| 1371 |
-
# client_id = input("Enter Mastodon Client Secret filename: ")
|
| 1372 |
-
# to_file = input("Save results to file (default = \"usercred.secret\"): ")
|
| 1373 |
-
# if to_file == "":
|
| 1374 |
-
# to_file = "usercred.secret"
|
| 1375 |
-
Tootbot.mastodon_login(username=username,
|
| 1376 |
-
password=password,
|
| 1377 |
-
redirect_uri=redirect_uri,
|
| 1378 |
-
client_id=client_id,
|
| 1379 |
-
to_file=to_file)
|
| 1380 |
-
|
| 1381 |
-
print("------------------------------------------------------------------")
|
| 1382 |
-
print("Initializing Models")
|
| 1383 |
-
print("------------------------------------------------------------------")
|
| 1384 |
-
diff_model = input("Enter Diffusion Model Name (Huggingface): ")
|
| 1385 |
-
if diff_model == "":
|
| 1386 |
-
diff_model = "stabilityai/stable-diffusion-2-1-base"
|
| 1387 |
-
keyword_model = input("Enter keyword extraction model name (if none, default is used): ")
|
| 1388 |
-
if keyword_model == "":
|
| 1389 |
-
keyword_model = "ml6team/keyphrase-extraction-distilbert-inspec"
|
| 1390 |
-
text_fail_classifier = "models/text-failed-classifier"
|
| 1391 |
-
dtype = input("Enter torch dtype (valid responses: [\"float32\", \"float16\"]): ")
|
| 1392 |
-
if dtype == "":
|
| 1393 |
-
dtype = "float32"
|
| 1394 |
-
device = input("Enter device (\"gpu\" or \"cpu\"): ")
|
| 1395 |
-
if device == "":
|
| 1396 |
-
device = "gpu"
|
| 1397 |
-
Tootbot.init_models(diffusion_model=diff_model,
|
| 1398 |
-
keyword_model=keyword_model,
|
| 1399 |
-
text_fail_classifier=text_fail_classifier,
|
| 1400 |
-
dtype="float32",
|
| 1401 |
-
device="cuda")
|
| 1402 |
-
print("------------------------------------------------------------------")
|
| 1403 |
-
print("Running Text generation")
|
| 1404 |
-
print("------------------------------------------------------------------")
|
| 1405 |
-
topic = input("Enter the topic for your toots/tweets: ")
|
| 1406 |
-
num_responses = int(input("Enter number of toots/tweets to generate: "))
|
| 1407 |
-
|
| 1408 |
-
save = input("Save results? (Y/n) ")
|
| 1409 |
-
if save == "Y" or save == "y":
|
| 1410 |
-
save = True
|
| 1411 |
-
elif save == "N" or save == "n":
|
| 1412 |
-
save = False
|
| 1413 |
-
with_images = input("Run with images? (Y/n) ")
|
| 1414 |
-
if with_images == "Y" or with_images == "y":
|
| 1415 |
-
with_images = True
|
| 1416 |
-
elif with_images == "N" or with_images == "n":
|
| 1417 |
-
with_images = False
|
| 1418 |
-
use_keyword_extractor = input("Use keyword extractor? (Y/n) ")
|
| 1419 |
-
if use_keyword_extractor == "Y" or use_keyword_extractor == "y":
|
| 1420 |
-
use_keyword_extractor = True
|
| 1421 |
-
elif use_keyword_extractor == "N" or use_keyword_extractor == "n":
|
| 1422 |
-
use_keyword_extractor = False
|
| 1423 |
-
image_tokens = input("Enter image tokens (ex: [black and white, year 2023]): ")
|
| 1424 |
-
image_tokens = [im.strip() for im in image_tokens.strip('][').replace("\"", "").split(',')]
|
| 1425 |
-
n = 50
|
| 1426 |
-
image_every_n_posts = 10
|
| 1427 |
-
folder = "images"
|
| 1428 |
-
topic_filename = topic.replace(" ", "-") + ".csv"
|
| 1429 |
-
Tootbot.reset_bot()
|
| 1430 |
-
new_data_df = Tootbot.run_bot_simulation(topic, num_responses=num_responses, n=n, save=True, filename=topic_filename)
|
| 1431 |
-
Tootbot.post(with_images=with_images, use_keyword_extractor=use_keyword_extractor, image_every_n_posts=image_every_n_posts, folder=folder, image_tokens=image_tokens)
|
| 1432 |
-
print("------------------------------------------------------------------")
|
| 1433 |
-
print("APPLICATION FINISHED SUCCESSFULLY")
|
| 1434 |
-
print("View results at https://bot-simulation-research.app/home")
|
| 1435 |
-
print("------------------------------------------------------------------")
|
|
|
|
| 1335 |
"""
|
| 1336 |
model_id = model_id
|
| 1337 |
self.keyword_model = KeyphraseExtractionPipeline(model=model_id)
|
| 1338 |
+
print(f"Keyword Extractor model {model_id} initialized")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|