Spaces:
Runtime error
Runtime error
"~"
Browse files- __pycache__/dataset.cpython-39.pyc +0 -0
- __pycache__/model.cpython-39.pyc +0 -0
- __pycache__/utils.cpython-39.pyc +0 -0
- app.py +49 -29
__pycache__/dataset.cpython-39.pyc
ADDED
Binary file (2.55 kB). View file
|
|
__pycache__/model.cpython-39.pyc
ADDED
Binary file (1.99 kB). View file
|
|
__pycache__/utils.cpython-39.pyc
ADDED
Binary file (2.72 kB). View file
|
|
app.py
CHANGED
@@ -7,6 +7,8 @@ from model import SeqTagger
|
|
7 |
from dataset import SeqTaggingClsDataset
|
8 |
from typing import Dict
|
9 |
import torch
|
|
|
|
|
10 |
|
11 |
# Disable cudnn to ensure the model runs on CPU
|
12 |
torch.backends.cudnn.enabled = False
|
@@ -65,7 +67,7 @@ best_model.load_state_dict(checkpoint['model_state_dict'])
|
|
65 |
# Set the model to evaluation mode
|
66 |
best_model.eval()
|
67 |
|
68 |
-
def
|
69 |
# Tokenize the text
|
70 |
str_text = [str(text.split())]
|
71 |
dic_text = {"tokens": str_text, "tags": [None], "id": ["text-0"]}
|
@@ -87,33 +89,51 @@ def classify(text: str):
|
|
87 |
|
88 |
text_tags = []
|
89 |
for i, tag in enumerate(preds[0]):
|
90 |
-
|
91 |
-
text_tags.extend([(text.split()[i], None), (" ", None)])
|
92 |
-
else:
|
93 |
-
text_tags.extend([(text.split()[i], tag), (" ", None)])
|
94 |
-
|
95 |
return text_tags
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
from dataset import SeqTaggingClsDataset
|
8 |
from typing import Dict
|
9 |
import torch
|
10 |
+
from gradio.components import Textbox
|
11 |
+
import random
|
12 |
|
13 |
# Disable cudnn to ensure the model runs on CPU
|
14 |
torch.backends.cudnn.enabled = False
|
|
|
67 |
# Set the model to evaluation mode
|
68 |
best_model.eval()
|
69 |
|
70 |
+
def tagging(text: str):
|
71 |
# Tokenize the text
|
72 |
str_text = [str(text.split())]
|
73 |
dic_text = {"tokens": str_text, "tags": [None], "id": ["text-0"]}
|
|
|
89 |
|
90 |
text_tags = []
|
91 |
for i, tag in enumerate(preds[0]):
|
92 |
+
text_tags.extend([(text.split()[i], tag), (" ", None)])
|
|
|
|
|
|
|
|
|
93 |
return text_tags
|
94 |
|
95 |
+
examples=[
|
96 |
+
"i have three people for august seventh",
|
97 |
+
"a table for 2 adults and 4 children please",
|
98 |
+
"i have a booking tomorrow for chara conelly at 9pm",
|
99 |
+
"me and 4 others will be there at 8:30pm",
|
100 |
+
"probably malik belliard has done the booking and it is on in 10 days",
|
101 |
+
"i want to book a table for me and my wife tonight at 6 p.m",
|
102 |
+
"date 18th of december",
|
103 |
+
"The concert is on September fifteenth",
|
104 |
+
"I need a reservation for a party of eight on Sunday",
|
105 |
+
"Her birthday is on May twenty-third",
|
106 |
+
"We have a meeting at ten a.m. tomorrow",
|
107 |
+
"The conference starts at eight o'clock in the morning",
|
108 |
+
"He booked a flight for February seventh",
|
109 |
+
"There is an event on the twenty-ninth of June",
|
110 |
+
"Please reserve a table for two for this evening",
|
111 |
+
"The project deadline is on March fourth",
|
112 |
+
"We'll have a gathering on the first of July"
|
113 |
+
]
|
114 |
+
|
115 |
+
def random_sample():
|
116 |
+
random_number = random.randint(0, len(examples) - 1)
|
117 |
+
return examples[random_number]
|
118 |
+
|
119 |
+
description="""
|
120 |
+
# Slot Tagging
|
121 |
+
This is a demo for slot tagging. Enter a sentence, and it will predict and highlight the slots.
|
122 |
+
"""
|
123 |
+
|
124 |
+
title="Slot Tagging"
|
125 |
+
|
126 |
+
with gr.Blocks(theme=gr.themes.Soft(), title=title) as demo:
|
127 |
+
gr.Markdown(description)
|
128 |
+
|
129 |
+
with gr.Row():
|
130 |
+
C_input = Textbox(lines=3, label="Context", placeholder="Please enter a text...")
|
131 |
+
T_output = gr.HighlightedText(lines=3, label="IOB Tagging")
|
132 |
+
with gr.Row():
|
133 |
+
random_button = gr.Button("Random")
|
134 |
+
tagging_button = gr.Button("Tagging")
|
135 |
+
|
136 |
+
random_button.click(random_sample, inputs=None, outputs=C_input)
|
137 |
+
tagging_button.click(tagging, inputs=C_input, outputs=T_output)
|
138 |
+
|
139 |
+
demo.launch()
|