Vjay15 commited on
Commit
afdae36
·
verified ·
1 Parent(s): b3c227f

feat: Add prompt picker and some ui enhancements

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -11,6 +11,33 @@ model.eval()
11
 
12
  LABELS = ["A", "B", "C", "D", "E"]
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  @spaces.GPU
16
  def predict(text):
@@ -43,10 +70,7 @@ def predict(text):
43
  probs = torch.softmax(model(**inputs).logits, dim=1)[0]
44
 
45
  prediction = LABELS[torch.argmax(probs).item()]
46
- confidence = {
47
- label: f"{prob.item() * 100:.2f}%"
48
- for label, prob in zip(LABELS, probs)
49
- }
50
  return prediction, confidence
51
 
52
 
@@ -64,8 +88,16 @@ E: Rome"""
64
  ),
65
  outputs=[
66
  gr.Textbox(label="Predicted Answer"),
67
- gr.JSON(label="Confidence Scores"),
 
 
 
 
 
 
 
68
  ],
 
69
  title="MCQ Solver",
70
  description="""
71
  A multiple-choice question answering system fine-tuned from Google's ELECTRA Base Discriminator model (`google/electra-base-discriminator`).
@@ -78,8 +110,9 @@ B: <option B>
78
  C: <option C>
79
  D: <option D>
80
  E: <option E>
81
- """
 
82
  )
83
 
84
  if __name__ == "__main__":
85
- demo.launch()
 
11
 
12
  LABELS = ["A", "B", "C", "D", "E"]
13
 
14
+ EXAMPLES = [
15
+ ["""Prompt: What is the function of mammary glands in mammals?
16
+ A: Mammary glands produce milk to feed the young.
17
+ B: Mammary glands help mammals draw air into the lungs.
18
+ C: Mammary glands help mammals breathe with lungs.
19
+ D: Mammary glands excrete nitrogenous waste as urea.
20
+ E: Mammary glands separate oxygenated and deoxygenated blood in the mammalian heart."""],
21
+ ["""Prompt: Who was the first to determine the velocity of a star moving away from the Earth using the Doppler effect?
22
+ A: Fraunhofer
23
+ B: William Huggins
24
+ C: Hippolyte Fizeau
25
+ D: Vogel and Scheiner
26
+ E: None of the above"""],
27
+ ["""Prompt: What is the effect generated by a spinning superconductor?
28
+ A: An electric field, precisely aligned with the spin axis.
29
+ B: A magnetic field, randomly aligned with the spin axis.
30
+ C: A magnetic field, precisely aligned with the spin axis.
31
+ D: A gravitational field, randomly aligned with the spin axis.
32
+ E: A gravitational field, precisely aligned with the spin axis."""],
33
+ ["""Prompt: What is bollard pull primarily used for measuring?
34
+ A: The weight of heavy machinery
35
+ B: The speed of locomotives
36
+ C: The distance traveled by a truck
37
+ D: The strength of tugboats
38
+ E: The height of a ballast tractor"""],
39
+ ]
40
+
41
 
42
  @spaces.GPU
43
  def predict(text):
 
70
  probs = torch.softmax(model(**inputs).logits, dim=1)[0]
71
 
72
  prediction = LABELS[torch.argmax(probs).item()]
73
+ confidence = {label: prob.item() for label, prob in zip(LABELS, probs)}
 
 
 
74
  return prediction, confidence
75
 
76
 
 
88
  ),
89
  outputs=[
90
  gr.Textbox(label="Predicted Answer"),
91
+ gr.Label(label="Confidence Scores", num_top_classes=5),
92
+ ],
93
+ examples=EXAMPLES,
94
+ example_labels=[
95
+ "What is the function of mammary glands in mammals?",
96
+ "Who was the first to determine the velocity of a star moving away from the Earth using the Doppler effect?",
97
+ "What is the effect generated by a spinning superconductor?",
98
+ "What is bollard pull primarily used for measuring?",
99
  ],
100
+ cache_examples=False,
101
  title="MCQ Solver",
102
  description="""
103
  A multiple-choice question answering system fine-tuned from Google's ELECTRA Base Discriminator model (`google/electra-base-discriminator`).
 
110
  C: <option C>
111
  D: <option D>
112
  E: <option E>
113
+ """,
114
+ flagging_mode="never",
115
  )
116
 
117
  if __name__ == "__main__":
118
+ demo.launch(theme=gr.themes.Soft())