User1342 commited on
Commit
768a35d
1 Parent(s): b229658

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -111,15 +111,9 @@ my_access_token = os.getenv('ACCESS_TOKEN')
111
  my_access_secret = os.getenv('ACCESS_SECRET')
112
  bearer = os.getenv('BEARER')
113
 
114
-
115
  global_oauth1_user_handler = None
116
 
117
- oauth1_user_handler = tweepy.OAuth1UserHandler(
118
- consumer_token, consumer_secret,
119
- callback="https://hf.space/embed/User1342/WatchTower/"
120
- )
121
- target_website = oauth1_user_handler.get_authorization_url(signin_with_twitter=True)
122
- print("target website is {}".format(target_website))
123
  block = gr.Blocks(css=".container { max-width: 800px; margin: auto; }")
124
 
125
  chat_history = []
@@ -128,7 +122,7 @@ chat_history = []
128
  def get_client_from_tokens(oauth_verifier, oauth_token):
129
  new_oauth1_user_handler = tweepy.OAuth1UserHandler(
130
  consumer_token, consumer_secret,
131
- callback="https://hf.space/embed/User1342/WatchTower/"
132
  )
133
  new_oauth1_user_handler.request_token = {
134
  "oauth_token": oauth_token,
@@ -140,6 +134,7 @@ def get_client_from_tokens(oauth_verifier, oauth_token):
140
  )
141
 
142
  their_client = tweepy.Client(
 
143
  consumer_key=consumer_token,
144
  consumer_secret=consumer_secret,
145
  access_token=access_token,
@@ -195,7 +190,7 @@ def chat(selected_option=None,radio_score=None, url_params = None):
195
  client = get_client_from_tokens(url_params["oauth_verifier"], url_params["oauth_token"])
196
  if radio_score != None and selected_option != None:
197
 
198
- if client != None and url_params != None:
199
  history.append(
200
  ["Model tuned to a '{}%' threshold and is using the '{}' dataset.".format(radio_score, selected_option),
201
  "{} Account blocking initialised".format(str(selected_option).capitalize())])
@@ -225,7 +220,7 @@ def predict(slider_value, url_params):
225
  print(url_params)
226
  return [None,chat(radio.value, slider_value, url_params)]
227
 
228
-
229
  def changed_tab():
230
  global have_initialised
231
  global chatbot
@@ -242,6 +237,14 @@ def changed_tab():
242
  chatbot.value = chat_history
243
  chatbot.update(value=chat_history)
244
 
 
 
 
 
 
 
 
 
245
  get_window_url_params = """
246
  function(text_input, url_params) {
247
  console.log(text_input, url_params);
@@ -307,4 +310,13 @@ with block:
307
  outputs=[text_output, chatbot], _js=get_window_url_params)
308
  tabs.change(fn=changed_tab, inputs=None, outputs=None)
309
 
 
 
 
 
 
 
 
 
 
310
  block.launch(enable_queue=False)
 
111
  my_access_secret = os.getenv('ACCESS_SECRET')
112
  bearer = os.getenv('BEARER')
113
 
 
114
  global_oauth1_user_handler = None
115
 
116
+
 
 
 
 
 
117
  block = gr.Blocks(css=".container { max-width: 800px; margin: auto; }")
118
 
119
  chat_history = []
 
122
  def get_client_from_tokens(oauth_verifier, oauth_token):
123
  new_oauth1_user_handler = tweepy.OAuth1UserHandler(
124
  consumer_token, consumer_secret,
125
+ callback="http://127.0.0.1:7860/"
126
  )
127
  new_oauth1_user_handler.request_token = {
128
  "oauth_token": oauth_token,
 
134
  )
135
 
136
  their_client = tweepy.Client(
137
+ bearer_token=bearer,
138
  consumer_key=consumer_token,
139
  consumer_secret=consumer_secret,
140
  access_token=access_token,
 
190
  client = get_client_from_tokens(url_params["oauth_verifier"], url_params["oauth_token"])
191
  if radio_score != None and selected_option != None:
192
 
193
+ if client != None:
194
  history.append(
195
  ["Model tuned to a '{}%' threshold and is using the '{}' dataset.".format(radio_score, selected_option),
196
  "{} Account blocking initialised".format(str(selected_option).capitalize())])
 
220
  print(url_params)
221
  return [None,chat(radio.value, slider_value, url_params)]
222
 
223
+ target_website = None
224
  def changed_tab():
225
  global have_initialised
226
  global chatbot
 
237
  chatbot.value = chat_history
238
  chatbot.update(value=chat_history)
239
 
240
+ oauth1_user_handler = tweepy.OAuth1UserHandler(
241
+ consumer_token, consumer_secret,
242
+ callback="http://127.0.0.1:7860/"
243
+ )
244
+ global target_website
245
+ target_website = oauth1_user_handler.get_authorization_url(signin_with_twitter=True)
246
+
247
+
248
  get_window_url_params = """
249
  function(text_input, url_params) {
250
  console.log(text_input, url_params);
 
310
  outputs=[text_output, chatbot], _js=get_window_url_params)
311
  tabs.change(fn=changed_tab, inputs=None, outputs=None)
312
 
313
+ gr.Markdown(
314
+ """___
315
+ <p style='text-align: center'>
316
+ Created by <a href="https://twitter.com/_JamesStevenson" target="_blank"James Stevenson</a> et al. 2021-2022
317
+ <br/>
318
+ <a href="https://github.com/CartographerLabs/Pinpoint" target="_blank">GitHub</a>
319
+ </p>"""
320
+ )
321
+
322
  block.launch(enable_queue=False)