Kaushik Bar
commited on
Commit
·
7dd13e4
1
Parent(s):
5da0eba
first commit
Browse files
app.py
CHANGED
@@ -56,22 +56,21 @@ def prep_examples():
|
|
56 |
example_labels11 = "bhalo;;kharap"
|
57 |
|
58 |
examples = [
|
59 |
-
[example_text1, example_labels1],
|
60 |
-
[example_text2, example_labels2],
|
61 |
-
[example_text3, example_labels3],
|
62 |
-
[example_text4, example_labels4],
|
63 |
-
[example_text5, example_labels5],
|
64 |
-
[example_text6, example_labels6],
|
65 |
-
[example_text7, example_labels7],
|
66 |
-
[example_text8, example_labels8],
|
67 |
-
[example_text9, example_labels9],
|
68 |
-
[example_text10, example_labels10],
|
69 |
-
[example_text11, example_labels11]]
|
70 |
|
71 |
return examples
|
72 |
|
73 |
def detect_lang(text):
|
74 |
-
DetectorFactory.seed = 0
|
75 |
seq_lang = 'en'
|
76 |
|
77 |
text = text.replace('\n', ' ')
|
@@ -86,15 +85,17 @@ def detect_lang(text):
|
|
86 |
|
87 |
return seq_lang
|
88 |
|
89 |
-
def sequence_to_classify(text, labels):
|
90 |
lang = detect_lang(text)
|
|
|
|
|
91 |
if lang == 'en':
|
92 |
model = model_en
|
93 |
hypothesis_template = "{}"
|
94 |
else:
|
95 |
model = model_multi
|
96 |
hypothesis_template = "{}"
|
97 |
-
|
98 |
labels = [hypothesis_template.format(label) for label in labels.split(";;")]
|
99 |
|
100 |
if str(type(model)) == "<class 'clip.model.CLIP'>":
|
@@ -124,6 +125,7 @@ def sequence_to_classify(text, labels):
|
|
124 |
pred["scores"], pred["labels"] = zip(*sorted_sl)
|
125 |
preds.append(pred)
|
126 |
|
|
|
127 |
if len(preds) == 1:
|
128 |
preds = preds[0]
|
129 |
|
@@ -148,7 +150,10 @@ iface = gr.Interface(
|
|
148 |
placeholder="Text here..."),
|
149 |
gr.inputs.Textbox(lines=2,
|
150 |
label="Please enter the candidate labels (separated by 2 consecutive semicolons)...",
|
151 |
-
placeholder="Labels here separated by ;;")
|
|
|
|
|
|
|
152 |
outputs=gr.outputs.Label(num_top_classes=5),
|
153 |
#interpretation="default",
|
154 |
examples=prep_examples())
|
|
|
56 |
example_labels11 = "bhalo;;kharap"
|
57 |
|
58 |
examples = [
|
59 |
+
[example_text1, example_labels1, "{}"],
|
60 |
+
[example_text2, example_labels2, "{}"],
|
61 |
+
[example_text3, example_labels3, "{}"],
|
62 |
+
[example_text4, example_labels4, "{}"],
|
63 |
+
[example_text5, example_labels5, "{}"],
|
64 |
+
[example_text6, example_labels6, "{}"],
|
65 |
+
[example_text7, example_labels7, "{}"],
|
66 |
+
[example_text8, example_labels8, "{}"],
|
67 |
+
[example_text9, example_labels9, "{}"],
|
68 |
+
[example_text10, example_labels10, "{}"],
|
69 |
+
[example_text11, example_labels11, "{}"]]
|
70 |
|
71 |
return examples
|
72 |
|
73 |
def detect_lang(text):
|
|
|
74 |
seq_lang = 'en'
|
75 |
|
76 |
text = text.replace('\n', ' ')
|
|
|
85 |
|
86 |
return seq_lang
|
87 |
|
88 |
+
def sequence_to_classify(text, labels, hypothesis_template):
|
89 |
lang = detect_lang(text)
|
90 |
+
|
91 |
+
print("hypothesis_template", hypothesis_template)
|
92 |
if lang == 'en':
|
93 |
model = model_en
|
94 |
hypothesis_template = "{}"
|
95 |
else:
|
96 |
model = model_multi
|
97 |
hypothesis_template = "{}"
|
98 |
+
|
99 |
labels = [hypothesis_template.format(label) for label in labels.split(";;")]
|
100 |
|
101 |
if str(type(model)) == "<class 'clip.model.CLIP'>":
|
|
|
125 |
pred["scores"], pred["labels"] = zip(*sorted_sl)
|
126 |
preds.append(pred)
|
127 |
|
128 |
+
print(preds)
|
129 |
if len(preds) == 1:
|
130 |
preds = preds[0]
|
131 |
|
|
|
150 |
placeholder="Text here..."),
|
151 |
gr.inputs.Textbox(lines=2,
|
152 |
label="Please enter the candidate labels (separated by 2 consecutive semicolons)...",
|
153 |
+
placeholder="Labels here separated by ;;"),
|
154 |
+
gr.inputs.Textbox(lines=2,
|
155 |
+
label="Please enter the text for hypothesis template(optional)...",
|
156 |
+
placeholder="Text here...")],
|
157 |
outputs=gr.outputs.Label(num_top_classes=5),
|
158 |
#interpretation="default",
|
159 |
examples=prep_examples())
|