Spaces:
Running
Running
Eric Mitchell commited on
Commit ·
a062447
1
Parent(s): a3e8f7b
Added error handling.
Browse files
app.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import matplotlib.pyplot as plt
|
| 3 |
import functools
|
| 4 |
import requests
|
| 5 |
import math
|
| 6 |
-
import plotly as py
|
| 7 |
import plotly.express as px
|
| 8 |
|
| 9 |
|
|
@@ -55,6 +53,8 @@ def detect(text):
|
|
| 55 |
x = requests.post(GET_RESULT, data={'text': text}, headers=headers).json()
|
| 56 |
response = x['result']
|
| 57 |
status = x['status']
|
|
|
|
|
|
|
| 58 |
|
| 59 |
original_score = response[0]
|
| 60 |
perturbed_scores = response[1]
|
|
@@ -171,7 +171,7 @@ def detect(text):
|
|
| 171 |
PERTURBATION_LOGPS = perturbed_scores
|
| 172 |
DATAFRAME_PAGE = 0
|
| 173 |
|
| 174 |
-
return fig, update_perturbations_dataframe(), result, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 175 |
|
| 176 |
|
| 177 |
def generate(text):
|
|
@@ -187,7 +187,7 @@ def update_perturbations_dataframe():
|
|
| 187 |
perturbed_texts = PERTURBATIONS[DATAFRAME_PAGE * PERTURBATIONS_PER_PAGE: (DATAFRAME_PAGE + 1) * PERTURBATIONS_PER_PAGE]
|
| 188 |
perturbed_scores = PERTURBATION_LOGPS[DATAFRAME_PAGE * PERTURBATIONS_PER_PAGE: (DATAFRAME_PAGE + 1) * PERTURBATIONS_PER_PAGE]
|
| 189 |
data = [[t, s] for t, s in zip(perturbed_texts, perturbed_scores)]
|
| 190 |
-
return gr.Dataframe.update(data)
|
| 191 |
|
| 192 |
|
| 193 |
|
|
@@ -290,8 +290,8 @@ with gr.Blocks() as demo:
|
|
| 290 |
with gr.Column(scale=8):
|
| 291 |
pass
|
| 292 |
detect_results_text = gr.Markdown()
|
| 293 |
-
results_plot = gr.Plot()
|
| 294 |
-
perturbations_dataframe = gr.DataFrame(label="Perturbed texts", headers=['Perturbed Text', 'Log Prob'], datatype=["str", "number"], wrap=True, max_rows=5)
|
| 295 |
|
| 296 |
page_label = gr.Markdown("Page 1", visible=False)
|
| 297 |
next_page_button = gr.Button("Next Page", visible=False)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import functools
|
| 3 |
import requests
|
| 4 |
import math
|
|
|
|
| 5 |
import plotly.express as px
|
| 6 |
|
| 7 |
|
|
|
|
| 53 |
x = requests.post(GET_RESULT, data={'text': text}, headers=headers).json()
|
| 54 |
response = x['result']
|
| 55 |
status = x['status']
|
| 56 |
+
if status != 'OK':
|
| 57 |
+
return gr.update(visible=False), gr.update(visible=False), status, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 58 |
|
| 59 |
original_score = response[0]
|
| 60 |
perturbed_scores = response[1]
|
|
|
|
| 171 |
PERTURBATION_LOGPS = perturbed_scores
|
| 172 |
DATAFRAME_PAGE = 0
|
| 173 |
|
| 174 |
+
return gr.update(value=fig, visible=True), update_perturbations_dataframe(), gr.update(value=result, visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 175 |
|
| 176 |
|
| 177 |
def generate(text):
|
|
|
|
| 187 |
perturbed_texts = PERTURBATIONS[DATAFRAME_PAGE * PERTURBATIONS_PER_PAGE: (DATAFRAME_PAGE + 1) * PERTURBATIONS_PER_PAGE]
|
| 188 |
perturbed_scores = PERTURBATION_LOGPS[DATAFRAME_PAGE * PERTURBATIONS_PER_PAGE: (DATAFRAME_PAGE + 1) * PERTURBATIONS_PER_PAGE]
|
| 189 |
data = [[t, s] for t, s in zip(perturbed_texts, perturbed_scores)]
|
| 190 |
+
return gr.Dataframe.update(data, visible=True)
|
| 191 |
|
| 192 |
|
| 193 |
|
|
|
|
| 290 |
with gr.Column(scale=8):
|
| 291 |
pass
|
| 292 |
detect_results_text = gr.Markdown()
|
| 293 |
+
results_plot = gr.Plot(visible=False)
|
| 294 |
+
perturbations_dataframe = gr.DataFrame(label="Perturbed texts", headers=['Perturbed Text', 'Log Prob'], datatype=["str", "number"], wrap=True, max_rows=5, visible=False)
|
| 295 |
|
| 296 |
page_label = gr.Markdown("Page 1", visible=False)
|
| 297 |
next_page_button = gr.Button("Next Page", visible=False)
|