NatanGarMar commited on
Commit
2233766
1 Parent(s): 2815585

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -11,8 +11,15 @@ labels = learner.dls.vocab
11
 
12
  # Definimos una función que se encarga de llevar a cabo las predicciones
13
  def predict(text):
14
- pred, pred_idx, probs = learner.predict(text)
15
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
 
 
 
 
 
 
16
 
17
  # Creamos la interfaz y la lanzamos
18
  gr.Interface(fn=predict, inputs=gr.inputs.Textbox(lines=2, placeholder="Finantial Sentence"), outputs=gr.outputs.Label(num_top_classes=3), examples=['text1.txt', 'text2.txt']).launch(share=False)
 
11
 
12
  # Definimos una función que se encarga de llevar a cabo las predicciones
13
  def predict(text):
14
+ result = learner.predict(text)
15
+ if len(result) == 3:
16
+ pred, pred_idx, probs = result
17
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
18
+ elif len(result) == 2:
19
+ pred, probs = result
20
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
21
+ else:
22
+ return {"Error": "Unexpected output format from learner"}
23
 
24
  # Creamos la interfaz y la lanzamos
25
  gr.Interface(fn=predict, inputs=gr.inputs.Textbox(lines=2, placeholder="Finantial Sentence"), outputs=gr.outputs.Label(num_top_classes=3), examples=['text1.txt', 'text2.txt']).launch(share=False)