da03 commited on
Commit
70487ef
1 Parent(s): 3f861c3
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -18,13 +18,6 @@ def postprocess(raw_output):
18
 
19
  @spaces.GPU
20
  def predict_product(num1, num2):
21
- try:
22
- num1_int = int(num1)
23
- num2_int = int(num2)
24
- valid_input = True
25
- except ValueError:
26
- valid_input = False
27
-
28
  input_text = f'{preprocess(num1)} * {preprocess(num2)} ='
29
  inputs = tokenizer(input_text, return_tensors='pt').to('cuda' if torch.cuda.is_available() else 'cpu')
30
  model.to('cuda' if torch.cuda.is_available() else 'cpu')
@@ -33,6 +26,13 @@ def predict_product(num1, num2):
33
  raw_output = tokenizer.decode(output, skip_special_tokens=True)
34
  prediction = postprocess(raw_output)
35
 
 
 
 
 
 
 
 
36
  if valid_input:
37
  correct_product = str(num1_int * num2_int)
38
  is_correct = (prediction == correct_product)
@@ -42,7 +42,9 @@ def predict_product(num1, num2):
42
  result_color = "black"
43
  result_message = "Invalid input. Could not evaluate correctness."
44
 
45
- return input_text, raw_output, prediction, result_message
 
 
46
 
47
  demo = gr.Interface(
48
  fn=predict_product,
 
18
 
19
  @spaces.GPU
20
  def predict_product(num1, num2):
 
 
 
 
 
 
 
21
  input_text = f'{preprocess(num1)} * {preprocess(num2)} ='
22
  inputs = tokenizer(input_text, return_tensors='pt').to('cuda' if torch.cuda.is_available() else 'cpu')
23
  model.to('cuda' if torch.cuda.is_available() else 'cpu')
 
26
  raw_output = tokenizer.decode(output, skip_special_tokens=True)
27
  prediction = postprocess(raw_output)
28
 
29
+ try:
30
+ num1_int = int(num1)
31
+ num2_int = int(num2)
32
+ valid_input = True
33
+ except ValueError:
34
+ valid_input = False
35
+
36
  if valid_input:
37
  correct_product = str(num1_int * num2_int)
38
  is_correct = (prediction == correct_product)
 
42
  result_color = "black"
43
  result_message = "Invalid input. Could not evaluate correctness."
44
 
45
+ result_html = f"<div style='color: {result_color};'>{result_message}</div>"
46
+
47
+ return input_text, raw_output, prediction, result_html
48
 
49
  demo = gr.Interface(
50
  fn=predict_product,