Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,10 @@ import numpy as np
|
|
3 |
import gradio as gr
|
4 |
import torch
|
5 |
from transformers import AutoModelForMultipleChoice, AutoTokenizer
|
6 |
-
from huggingface_hub import hf_hub_url, Repository
|
7 |
-
model_id="deepset/deberta-v3-large-squad2"
|
8 |
-
# Load the model and tokenizer
|
9 |
|
|
|
|
|
|
|
10 |
model = AutoModelForMultipleChoice.from_pretrained(model_id)
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
12 |
|
@@ -28,12 +28,13 @@ def predict(data):
|
|
28 |
predictions_as_ids = torch.argsort(-logits, dim=1)
|
29 |
answers = np.array(list("ABCDE"))[predictions_as_ids.tolist()]
|
30 |
return ["".join(i) for i in answers[:, :3]]
|
31 |
-
|
|
|
32 |
# Create the Gradio interface
|
33 |
iface = gr.Interface(
|
34 |
fn=predict,
|
35 |
-
inputs=
|
36 |
-
outputs=
|
37 |
live=True,
|
38 |
examples=[
|
39 |
{"prompt": "This is the prompt", "A": "Option A text", "B": "Option B text", "C": "Option C text", "D": "Option D text", "E": "Option E text"}
|
@@ -43,4 +44,4 @@ iface = gr.Interface(
|
|
43 |
)
|
44 |
|
45 |
# Run the interface
|
46 |
-
iface.launch(
|
|
|
3 |
import gradio as gr
|
4 |
import torch
|
5 |
from transformers import AutoModelForMultipleChoice, AutoTokenizer
|
|
|
|
|
|
|
6 |
|
7 |
+
model_id = "deepset/deberta-v3-large-squad2"
|
8 |
+
|
9 |
+
# Load the model and tokenizer
|
10 |
model = AutoModelForMultipleChoice.from_pretrained(model_id)
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
12 |
|
|
|
28 |
predictions_as_ids = torch.argsort(-logits, dim=1)
|
29 |
answers = np.array(list("ABCDE"))[predictions_as_ids.tolist()]
|
30 |
return ["".join(i) for i in answers[:, :3]]
|
31 |
+
text=gr.Textbox(placeholder="paste multiple choice questions.....")
|
32 |
+
label=gr.Label(num_top_classes=3)
|
33 |
# Create the Gradio interface
|
34 |
iface = gr.Interface(
|
35 |
fn=predict,
|
36 |
+
inputs=text # Use the correct class with type="json"
|
37 |
+
outputs=label,
|
38 |
live=True,
|
39 |
examples=[
|
40 |
{"prompt": "This is the prompt", "A": "Option A text", "B": "Option B text", "C": "Option C text", "D": "Option D text", "E": "Option E text"}
|
|
|
44 |
)
|
45 |
|
46 |
# Run the interface
|
47 |
+
iface.launch()
|