Spaces:
Running on CPU Upgrade

ziem-io commited on
Commit
1e3cd55
·
1 Parent(s): 1529238

Update: Extra output block for info

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -90,12 +90,12 @@ def predict(review: str):
90
 
91
  review = (review or "").strip()
92
  is_translated = False
93
- html_out = ""
94
 
95
  # Abort if no text if given
96
  if not review:
97
- # immer zwei Outputs zurückgeben
98
- return "Please enter a review.", {}
99
 
100
  # Check for lang of text
101
  review_is_eng, review_lang_prob = _is_eng(review)
@@ -103,7 +103,7 @@ def predict(review: str):
103
  # Abort if text is not english
104
  if not review_is_eng:
105
  review = _translate_en(review)
106
- html_out += f"""<strong style='margin-bottom: 0.5em'>Your text has been automatically translated:</strong>
107
  <p>{review}</p>
108
  """
109
  is_translated = True
@@ -117,7 +117,7 @@ def predict(review: str):
117
  prediction_flavours_list = list(prediction_flavours.values())
118
  t_end_flavours = time.time()
119
 
120
- html_out += build_svg_with_values(prediction_flavours_list)
121
 
122
  json_out = {
123
  "results": [{
@@ -135,7 +135,7 @@ def predict(review: str):
135
  "duration": round((t_end_flavours - t_start_flavours), 3),
136
  }
137
 
138
- return html_out, json_out
139
 
140
  ##################################################################################
141
 
@@ -180,11 +180,12 @@ with gr.Blocks(css=custom_css) as demo:
180
  submit_btn = gr.Button("Submit", variant="primary", scale=1)
181
 
182
  with gr.Column(scale=1): # rechte Seite: Output
183
- html_out = gr.HTML(label="Flavour Wheel")
 
184
  json_out = gr.JSON(label="JSON")
185
 
186
  # Events
187
- submit_btn.click(predict, inputs=review_box, outputs=[html_out, json_out])
188
  replace_btn.click(random_text, outputs=review_box)
189
 
190
  demo.launch()
 
90
 
91
  review = (review or "").strip()
92
  is_translated = False
93
+ html_info_out = ""
94
 
95
  # Abort if no text if given
96
  if not review:
97
+ # immer drei Outputs zurückgeben
98
+ return "Please enter a review.", "", {}
99
 
100
  # Check for lang of text
101
  review_is_eng, review_lang_prob = _is_eng(review)
 
103
  # Abort if text is not english
104
  if not review_is_eng:
105
  review = _translate_en(review)
106
+ html_info_out = f"""<strong style='margin-bottom: 0.5em'>Your text has been automatically translated:</strong>
107
  <p>{review}</p>
108
  """
109
  is_translated = True
 
117
  prediction_flavours_list = list(prediction_flavours.values())
118
  t_end_flavours = time.time()
119
 
120
+ html_wheel_out = build_svg_with_values(prediction_flavours_list)
121
 
122
  json_out = {
123
  "results": [{
 
135
  "duration": round((t_end_flavours - t_start_flavours), 3),
136
  }
137
 
138
+ return html_info_out, html_wheel_out, json_out
139
 
140
  ##################################################################################
141
 
 
180
  submit_btn = gr.Button("Submit", variant="primary", scale=1)
181
 
182
  with gr.Column(scale=1): # rechte Seite: Output
183
+ html_info_out = gr.HTML(label="Info")
184
+ html_wheel_out = gr.HTML(label="Flavour Wheel")
185
  json_out = gr.JSON(label="JSON")
186
 
187
  # Events
188
+ submit_btn.click(predict, inputs=review_box, outputs=[html_info_out, html_wheel_out, json_out])
189
  replace_btn.click(random_text, outputs=review_box)
190
 
191
  demo.launch()