Cristóbal Hernández commited on
Commit
5d967c4
·
1 Parent(s): ec2757f

Add application file

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -51,12 +51,12 @@ def classify_output(item):
51
  if item['score'] >= 0.5:
52
  # Append the category and score to the classifications list
53
  classifications.append((label_dict[item['label']], item['score']))
54
-
55
  # Construct and print the classification message
56
  if classifications:
57
- classification_str = ', '.join([f"'{label}' ({score:.2f})" for label, score in classifications])
58
 
59
- output1 = f"The item you provided is classified as: {classification_str}"
60
  return output1
61
  else:
62
  output2 = f"No classifications with a score of 0.5 or higher were found. \n However, the highest probability was for: '{label_dict[highest_score_item['label']]}' ({round(item['score'],2)}) \n Use this classification with caution due to uncertainty"
@@ -66,7 +66,13 @@ def classify_output(item):
66
  ######## RUN GRADIO APP #################
67
  #########################################
68
 
69
- demo = gr.Interface(fn=classify_output, inputs="text", outputs="text")
70
- demo.launch()
 
 
 
 
 
 
71
 
72
 
 
51
  if item['score'] >= 0.5:
52
  # Append the category and score to the classifications list
53
  classifications.append((label_dict[item['label']], item['score']))
54
+
55
  # Construct and print the classification message
56
  if classifications:
57
+ classification_str = ', '.join([f"{label} ({score:.2f})" for label, score in classifications])
58
 
59
+ output1 = classification_str
60
  return output1
61
  else:
62
  output2 = f"No classifications with a score of 0.5 or higher were found. \n However, the highest probability was for: '{label_dict[highest_score_item['label']]}' ({round(item['score'],2)}) \n Use this classification with caution due to uncertainty"
 
66
  ######## RUN GRADIO APP #################
67
  #########################################
68
 
69
+ txtbx = gr.Textbox(value = 'I would like to feel better', label = 'Please enter your item:', container = 'True')
70
+ txtbxopt = gr.Textbox(label = 'The item you provided was classified as:', container = 'True')
71
+ demo = gr.Interface(fn=classify_output, inputs=txtbx, outputs=txtbxopt,
72
+ theme = gr.themes.Soft(primary_hue='orange'),
73
+ title = 'EEMM Item Classification Machine V 0.5',
74
+ description = 'This machine is a fine tuned version of DistillBERT. It classifies items in 7 EEMM dimensions following (ref). **Please note that the machine goes idle after a period of inactivity. If this occurs, waking it up may take around 20 seconds. Be patient ;)**',
75
+ article = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum')
76
+ demo.launch(share=True)
77
 
78