Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -113,8 +113,7 @@ 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 = []
|
120 |
|
@@ -221,8 +220,7 @@ def predict(slider_value, url_params):
|
|
221 |
return [None,chat(radio.value, slider_value, url_params)]
|
222 |
|
223 |
target_website = None
|
224 |
-
def changed_tab(
|
225 |
-
):
|
226 |
global have_initialised
|
227 |
global chatbot
|
228 |
global chat_history
|
@@ -237,13 +235,14 @@ def changed_tab(
|
|
237 |
|
238 |
chatbot.value = chat_history
|
239 |
chatbot.update(value=chat_history)
|
240 |
-
|
241 |
twitter_auth_button.value = '<a href={}><img src="https://cdn.cms-twdigitalassets.com/content/dam/developer-twitter/auth-docs/sign-in-with-twitter-gray.png.twimg.1920.png" alt="Log In With Twitter"></a><br>'.format(
|
242 |
-
|
243 |
twitter_auth_button.update(value= '<a href={}><img src="https://cdn.cms-twdigitalassets.com/content/dam/developer-twitter/auth-docs/sign-in-with-twitter-gray.png.twimg.1920.png" alt="Log In With Twitter"></a><br>'.format(
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
247 |
|
248 |
get_window_url_params = """
|
249 |
function(text_input, url_params) {
|
@@ -259,10 +258,15 @@ def get_target_website():
|
|
259 |
consumer_token, consumer_secret,
|
260 |
callback="https://hf.space/embed/User1342/WatchTower/"
|
261 |
)
|
262 |
-
target_website = oauth1_user_handler.get_authorization_url(signin_with_twitter=
|
263 |
|
264 |
return target_website
|
265 |
|
|
|
|
|
|
|
|
|
|
|
266 |
with block:
|
267 |
gr.HTML('''
|
268 |
|
@@ -290,7 +294,7 @@ with block:
|
|
290 |
|
291 |
prediction_tab = gr.TabItem("Getting Started")
|
292 |
with prediction_tab:
|
293 |
-
gr.HTML('''
|
294 |
<header class="w3-display-container w3-content w3-wide" style="max-height:250px;" id="home">
|
295 |
<img class="w3-image" src="https://cdn.pixabay.com/photo/2018/12/10/16/22/city-3867295_960_720.png" alt="Architecture" width="1500" height="800">
|
296 |
<div class="w3-display-middle w3-margin-top w3-center">
|
@@ -304,9 +308,7 @@ with block:
|
|
304 |
text_input = gr.Text(label="Input", visible=False)
|
305 |
text_output = gr.Text(label="Output", visible=False)
|
306 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
307 |
-
|
308 |
-
value='<a href={}><img src="https://cdn.cms-twdigitalassets.com/content/dam/developer-twitter/auth-docs/sign-in-with-twitter-gray.png.twimg.1920.png" alt="Log In With Twitter"></a><br>'.format(
|
309 |
-
None))
|
310 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
311 |
radio = gr.CheckboxGroup(value="Violent", choices=["Violent", "Hate Speech", "Misinformation"],
|
312 |
interactive=False, label="Behaviour To Block")
|
@@ -318,9 +320,7 @@ with block:
|
|
318 |
btn.click(fn=predict, inputs=[slider, url_params],
|
319 |
outputs=[text_output, chatbot], _js=get_window_url_params)
|
320 |
tabs.change(fn=changed_tab, inputs=None, outputs=None)
|
321 |
-
chatbot.set_event_trigger(event_name="load",fn=changed_tab
|
322 |
-
|
323 |
-
|
324 |
gr.Markdown(
|
325 |
"""___
|
326 |
<p style='text-align: center'>
|
@@ -330,5 +330,8 @@ with block:
|
|
330 |
</p>"""
|
331 |
)
|
332 |
|
333 |
-
block.
|
|
|
|
|
|
|
334 |
block.launch(enable_queue=False)
|
|
|
113 |
|
114 |
global_oauth1_user_handler = None
|
115 |
|
116 |
+
block = gr.Blocks(css=".container { max-width: 800px; margin: auto; }", title="WatchTower")
|
|
|
117 |
|
118 |
chat_history = []
|
119 |
|
|
|
220 |
return [None,chat(radio.value, slider_value, url_params)]
|
221 |
|
222 |
target_website = None
|
223 |
+
def changed_tab():
|
|
|
224 |
global have_initialised
|
225 |
global chatbot
|
226 |
global chat_history
|
|
|
235 |
|
236 |
chatbot.value = chat_history
|
237 |
chatbot.update(value=chat_history)
|
238 |
+
|
239 |
twitter_auth_button.value = '<a href={}><img src="https://cdn.cms-twdigitalassets.com/content/dam/developer-twitter/auth-docs/sign-in-with-twitter-gray.png.twimg.1920.png" alt="Log In With Twitter"></a><br>'.format(
|
240 |
+
get_target_website())
|
241 |
twitter_auth_button.update(value= '<a href={}><img src="https://cdn.cms-twdigitalassets.com/content/dam/developer-twitter/auth-docs/sign-in-with-twitter-gray.png.twimg.1920.png" alt="Log In With Twitter"></a><br>'.format(
|
242 |
+
get_target_website()))
|
243 |
+
|
244 |
+
return '<a href={}><img src="https://cdn.cms-twdigitalassets.com/content/dam/developer-twitter/auth-docs/sign-in-with-twitter-gray.png.twimg.1920.png" alt="Log In With Twitter"></a><br>'.format(
|
245 |
+
get_target_website())
|
246 |
|
247 |
get_window_url_params = """
|
248 |
function(text_input, url_params) {
|
|
|
258 |
consumer_token, consumer_secret,
|
259 |
callback="https://hf.space/embed/User1342/WatchTower/"
|
260 |
)
|
261 |
+
target_website = oauth1_user_handler.get_authorization_url(signin_with_twitter=True)
|
262 |
|
263 |
return target_website
|
264 |
|
265 |
+
|
266 |
+
twitter_auth_button = gr.HTML(
|
267 |
+
value='<a href={}><img src="https://cdn.cms-twdigitalassets.com/content/dam/developer-twitter/auth-docs/sign-in-with-twitter-gray.png.twimg.1920.png" alt="Log In With Twitter"></a><br>'.format(
|
268 |
+
get_target_website()))
|
269 |
+
|
270 |
with block:
|
271 |
gr.HTML('''
|
272 |
|
|
|
294 |
|
295 |
prediction_tab = gr.TabItem("Getting Started")
|
296 |
with prediction_tab:
|
297 |
+
html_button = gr.HTML('''
|
298 |
<header class="w3-display-container w3-content w3-wide" style="max-height:250px;" id="home">
|
299 |
<img class="w3-image" src="https://cdn.pixabay.com/photo/2018/12/10/16/22/city-3867295_960_720.png" alt="Architecture" width="1500" height="800">
|
300 |
<div class="w3-display-middle w3-margin-top w3-center">
|
|
|
308 |
text_input = gr.Text(label="Input", visible=False)
|
309 |
text_output = gr.Text(label="Output", visible=False)
|
310 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
311 |
+
twitter_auth_button
|
|
|
|
|
312 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
313 |
radio = gr.CheckboxGroup(value="Violent", choices=["Violent", "Hate Speech", "Misinformation"],
|
314 |
interactive=False, label="Behaviour To Block")
|
|
|
320 |
btn.click(fn=predict, inputs=[slider, url_params],
|
321 |
outputs=[text_output, chatbot], _js=get_window_url_params)
|
322 |
tabs.change(fn=changed_tab, inputs=None, outputs=None)
|
323 |
+
chatbot.set_event_trigger(event_name="load",fn=changed_tab)
|
|
|
|
|
324 |
gr.Markdown(
|
325 |
"""___
|
326 |
<p style='text-align: center'>
|
|
|
330 |
</p>"""
|
331 |
)
|
332 |
|
333 |
+
block.set_event_trigger(
|
334 |
+
event_name="load", fn=changed_tab, inputs=None, outputs=[html_button], no_target=True
|
335 |
+
)
|
336 |
+
|
337 |
block.launch(enable_queue=False)
|