Clémentine commited on
Commit
d614278
1 Parent(s): 2060c34

Explicited the error logs for the users

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -20,6 +20,7 @@ def query(payload):
20
  print(response)
21
  return json.loads(response.content.decode("utf-8"))
22
 
 
23
  def inference(input_sentence, max_length, sample_or_greedy, seed=42):
24
  if sample_or_greedy == "Sample":
25
  parameters = {
@@ -43,11 +44,10 @@ def inference(input_sentence, max_length, sample_or_greedy, seed=42):
43
 
44
  payload = {"inputs": input_sentence, "parameters": parameters}
45
 
46
- #if API_URL is not None:
47
  data = query(payload)
48
- #else: # To remove when plugged in a real API
49
- # input_sentence, generation = payload["inputs"].split("\n", 1)
50
- # data = [{"generated_text": input_sentence + generation}]
51
 
52
  generation = data[0]["generated_text"].split(input_sentence, 1)[1]
53
  return (
@@ -57,6 +57,7 @@ def inference(input_sentence, max_length, sample_or_greedy, seed=42):
57
  + generation
58
  + after_generation,
59
  data[0]["generated_text"],
 
60
  )
61
 
62
 
@@ -86,9 +87,9 @@ if __name__ == "__main__":
86
  submit = gr.Button("Submit")
87
  load_image = gr.Button("Generate Image")
88
  with gr.Column():
89
- display_out = gr.HTML(
90
- label="Image"
91
- ) # , visible=False) #interactive=True,
92
  display_out.set_event_trigger(
93
  "load",
94
  fn=None,
@@ -97,14 +98,13 @@ if __name__ == "__main__":
97
  no_target=True,
98
  js=js_load_script,
99
  )
100
- text_out = gr.Textbox(label="Output")
101
  with gr.Row():
102
- gr.Examples(examples=examples, inputs=[text, tokens, sampling, sampling2])
103
 
104
  submit.click(
105
  inference,
106
  inputs=[text, tokens, sampling, sampling2],
107
- outputs=[display_out, text_out],
108
  )
109
 
110
  load_image.click(fn=None, inputs=None, outputs=None, _js=js_save)
 
20
  print(response)
21
  return json.loads(response.content.decode("utf-8"))
22
 
23
+
24
  def inference(input_sentence, max_length, sample_or_greedy, seed=42):
25
  if sample_or_greedy == "Sample":
26
  parameters = {
 
44
 
45
  payload = {"inputs": input_sentence, "parameters": parameters}
46
 
 
47
  data = query(payload)
48
+
49
+ if "error" in data:
50
+ return (None, None, f"<span style='color:red'>ERROR: {data['error']} </span>")
51
 
52
  generation = data[0]["generated_text"].split(input_sentence, 1)[1]
53
  return (
 
57
  + generation
58
  + after_generation,
59
  data[0]["generated_text"],
60
+ "",
61
  )
62
 
63
 
 
87
  submit = gr.Button("Submit")
88
  load_image = gr.Button("Generate Image")
89
  with gr.Column():
90
+ text_error = gr.Markdown(label="Log information")
91
+ text_out = gr.Textbox(label="Output")
92
+ display_out = gr.HTML(label="Image")
93
  display_out.set_event_trigger(
94
  "load",
95
  fn=None,
 
98
  no_target=True,
99
  js=js_load_script,
100
  )
 
101
  with gr.Row():
102
+ gr.Examples(examples=examples, inputs=[text, tokens, sampling, sampling2])
103
 
104
  submit.click(
105
  inference,
106
  inputs=[text, tokens, sampling, sampling2],
107
+ outputs=[display_out, text_out, text_error],
108
  )
109
 
110
  load_image.click(fn=None, inputs=None, outputs=None, _js=js_save)