Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from generic import generate_visual
|
|
|
|
| 4 |
|
| 5 |
+
def generate_viz(text, target_class):
|
| 6 |
+
|
| 7 |
+
print(f"Input Text: {text_batch}")
|
| 8 |
+
print(f"Target Class: {target_class}")
|
| 9 |
+
text_batch=[]
|
| 10 |
+
text_batch.append(text)
|
| 11 |
+
token_import, html_page = generate_visual(text_batch=text_batch, target_class=target_class)
|
| 12 |
+
return token_importance, html1
|
| 13 |
+
|
| 14 |
+
title = "Explain BERT 😄"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(fn=generate_viz, inputs=[
|
| 18 |
+
gr.Text(label="Input Text"),
|
| 19 |
+
gr.Dropdown(
|
| 20 |
+
[0,1],
|
| 21 |
+
label="Target_Class",
|
| 22 |
+
info="0 is negative, 1 is positive",
|
| 23 |
+
),
|
| 24 |
+
],
|
| 25 |
+
outputs=[ gr.Text(label="Token_Importance"), gr.HTML(label="visualize sentence"),],
|
| 26 |
+
title=title,
|
| 27 |
+
allow_flagging="never",
|
| 28 |
+
cache_examples=True,
|
| 29 |
+
examples=[
|
| 30 |
+
["This movie was the best movie I have ever seen! some scenes were ridiculous, but acting was great.", 1],
|
| 31 |
+
["I really didn't like this movie. Some of the actors were good, but overall the movie was boring.", 0],
|
| 32 |
+
["I hate that I love you.", 0],
|
| 33 |
+
["I hate that I love you.", 1],
|
| 34 |
+
],
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
iface.launch(debug=True)
|