Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,31 +41,31 @@ def client_log_in():
|
|
| 41 |
|
| 42 |
global slider_choice
|
| 43 |
server = slider_choice
|
| 44 |
-
|
| 45 |
if server != None:
|
| 46 |
id = "WatchTower Ivory | Mastodon"
|
| 47 |
-
|
| 48 |
#client_id, client_secret = Mastodon.create_app(id,
|
| 49 |
# api_base_url= server, scopes=["write:blocks", "write:mutes"],
|
| 50 |
# redirect_uris="https://user1342-ivory.hf.space/",
|
| 51 |
# website="https://www.watchtower.cartographer.one/")
|
| 52 |
-
|
| 53 |
secrets = json.loads(os.getenv('secrets_json'))
|
| 54 |
-
|
| 55 |
print("server: {}".format(server))
|
| 56 |
print("server dict {}".format(secrets[server]))
|
| 57 |
-
|
| 58 |
client_id = secrets[server]["client_id"]
|
| 59 |
client_secret = secrets[server]["client_secret"]
|
| 60 |
password = secrets[server]["password"]
|
| 61 |
username = os.getenv('username')
|
| 62 |
-
|
| 63 |
-
|
| 64 |
mastodon = Mastodon(
|
| 65 |
client_id=client_id,client_secret=client_secret,
|
| 66 |
api_base_url='https://{}'.format(server)
|
| 67 |
)
|
| 68 |
-
|
| 69 |
access_token = mastodon.log_in(
|
| 70 |
username=username,
|
| 71 |
password=password,
|
|
@@ -101,12 +101,12 @@ def login_from_code(code):
|
|
| 101 |
secrets = json.loads(os.getenv('secrets_json'))
|
| 102 |
client_id = secrets[server]["client_id"]
|
| 103 |
client_secret = secrets[server]["client_secret"]
|
| 104 |
-
|
| 105 |
mastodon = Mastodon(
|
| 106 |
client_id=client_id, client_secret=client_secret,
|
| 107 |
api_base_url='https://{}'.format(server)
|
| 108 |
)
|
| 109 |
-
|
| 110 |
mastodon.log_in(code=code,
|
| 111 |
scopes=["write:blocks", "write:mutes"],
|
| 112 |
redirect_uri="https://user1342-ivory.hf.space/")
|
|
@@ -361,12 +361,16 @@ get_window_url_params = """
|
|
| 361 |
return [text_input, url_params];
|
| 362 |
}
|
| 363 |
"""
|
| 364 |
-
slider_choice =
|
| 365 |
def update_server(choice):
|
| 366 |
print("In change server")
|
| 367 |
global slider_choice
|
| 368 |
slider_choice = choice
|
| 369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
def get_chatbot_text():
|
| 371 |
return [('Welcome to Watchtower.', 'Log in via Mastodon and configure your blocking options above.')]
|
| 372 |
|
|
@@ -406,11 +410,11 @@ with block:
|
|
| 406 |
text_input = gr.Text(label="Input", visible=False).style()
|
| 407 |
text_output = gr.Text(label="Output", visible=False).style()
|
| 408 |
with gr.Row().style(equal_height=True):
|
|
|
|
| 409 |
html_button = mastodon_auth_button = gr.HTML(
|
| 410 |
value=auth_button_text.format(
|
| 411 |
get_target_website())).style(
|
| 412 |
)
|
| 413 |
-
dropdown = gr.Dropdown(choices=list_of_servers, label="Server")
|
| 414 |
with gr.Row().style(equal_height=True):
|
| 415 |
radio = gr.CheckboxGroup(value=["Violent", "Hate Speech"],
|
| 416 |
choices=["Violent", "Hate Speech", "Misinformation"],
|
|
@@ -423,7 +427,7 @@ with block:
|
|
| 423 |
color_map=["grey", "purple"])
|
| 424 |
|
| 425 |
btn = gr.Button("Run WatchTower").style(full_width=True).style()
|
| 426 |
-
dropdown.change(fn=update_server, inputs=[dropdown])
|
| 427 |
btn.click(fn=button_pressed, inputs=[slider, url_params],
|
| 428 |
outputs=[text_output, chatbot], _js=get_window_url_params)
|
| 429 |
gr.Markdown(
|
|
|
|
| 41 |
|
| 42 |
global slider_choice
|
| 43 |
server = slider_choice
|
| 44 |
+
|
| 45 |
if server != None:
|
| 46 |
id = "WatchTower Ivory | Mastodon"
|
| 47 |
+
|
| 48 |
#client_id, client_secret = Mastodon.create_app(id,
|
| 49 |
# api_base_url= server, scopes=["write:blocks", "write:mutes"],
|
| 50 |
# redirect_uris="https://user1342-ivory.hf.space/",
|
| 51 |
# website="https://www.watchtower.cartographer.one/")
|
| 52 |
+
|
| 53 |
secrets = json.loads(os.getenv('secrets_json'))
|
| 54 |
+
|
| 55 |
print("server: {}".format(server))
|
| 56 |
print("server dict {}".format(secrets[server]))
|
| 57 |
+
|
| 58 |
client_id = secrets[server]["client_id"]
|
| 59 |
client_secret = secrets[server]["client_secret"]
|
| 60 |
password = secrets[server]["password"]
|
| 61 |
username = os.getenv('username')
|
| 62 |
+
|
| 63 |
+
|
| 64 |
mastodon = Mastodon(
|
| 65 |
client_id=client_id,client_secret=client_secret,
|
| 66 |
api_base_url='https://{}'.format(server)
|
| 67 |
)
|
| 68 |
+
|
| 69 |
access_token = mastodon.log_in(
|
| 70 |
username=username,
|
| 71 |
password=password,
|
|
|
|
| 101 |
secrets = json.loads(os.getenv('secrets_json'))
|
| 102 |
client_id = secrets[server]["client_id"]
|
| 103 |
client_secret = secrets[server]["client_secret"]
|
| 104 |
+
|
| 105 |
mastodon = Mastodon(
|
| 106 |
client_id=client_id, client_secret=client_secret,
|
| 107 |
api_base_url='https://{}'.format(server)
|
| 108 |
)
|
| 109 |
+
|
| 110 |
mastodon.log_in(code=code,
|
| 111 |
scopes=["write:blocks", "write:mutes"],
|
| 112 |
redirect_uri="https://user1342-ivory.hf.space/")
|
|
|
|
| 361 |
return [text_input, url_params];
|
| 362 |
}
|
| 363 |
"""
|
| 364 |
+
slider_choice = list_of_servers[0]
|
| 365 |
def update_server(choice):
|
| 366 |
print("In change server")
|
| 367 |
global slider_choice
|
| 368 |
slider_choice = choice
|
| 369 |
|
| 370 |
+
get_target_website()
|
| 371 |
+
|
| 372 |
+
return auth_button_text.format(get_target_website())
|
| 373 |
+
|
| 374 |
def get_chatbot_text():
|
| 375 |
return [('Welcome to Watchtower.', 'Log in via Mastodon and configure your blocking options above.')]
|
| 376 |
|
|
|
|
| 410 |
text_input = gr.Text(label="Input", visible=False).style()
|
| 411 |
text_output = gr.Text(label="Output", visible=False).style()
|
| 412 |
with gr.Row().style(equal_height=True):
|
| 413 |
+
dropdown = gr.Dropdown(choices=list_of_servers, label="Server", value=list_of_servers[0])
|
| 414 |
html_button = mastodon_auth_button = gr.HTML(
|
| 415 |
value=auth_button_text.format(
|
| 416 |
get_target_website())).style(
|
| 417 |
)
|
|
|
|
| 418 |
with gr.Row().style(equal_height=True):
|
| 419 |
radio = gr.CheckboxGroup(value=["Violent", "Hate Speech"],
|
| 420 |
choices=["Violent", "Hate Speech", "Misinformation"],
|
|
|
|
| 427 |
color_map=["grey", "purple"])
|
| 428 |
|
| 429 |
btn = gr.Button("Run WatchTower").style(full_width=True).style()
|
| 430 |
+
dropdown.change(fn=update_server, inputs=[dropdown], outputs=html_button)
|
| 431 |
btn.click(fn=button_pressed, inputs=[slider, url_params],
|
| 432 |
outputs=[text_output, chatbot], _js=get_window_url_params)
|
| 433 |
gr.Markdown(
|