Kaushik Bar
commited on
Commit
•
5da0eba
1
Parent(s):
37fe09a
first commit
Browse files- app.py +6 -4
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
import datetime
|
2 |
import gradio as gr
|
3 |
-
from
|
4 |
import fasttext, torch, clip
|
5 |
from sentence_transformers import SentenceTransformer, util
|
6 |
|
7 |
model_en, _ = clip.load("ViT-B/32")
|
8 |
model_multi = SentenceTransformer("sentence-transformers/clip-ViT-B-32-multilingual-v1")
|
9 |
|
|
|
|
|
10 |
def prep_examples():
|
11 |
example_text1 = "Coronavirus disease (COVID-19) is an infectious disease caused by the SARS-CoV-2 virus. Most \
|
12 |
people who fall sick with COVID-19 will experience mild to moderate symptoms and recover without special treatment. \
|
@@ -78,7 +80,7 @@ def detect_lang(text):
|
|
78 |
seq_lang = fasttext_model.predict(text, k=1)[0][0].split("__label__")[1]
|
79 |
except:
|
80 |
print("Language detection failed!",
|
81 |
-
"Date:{}, Sequence:{}".format(
|
82 |
str(datetime.datetime.now()),
|
83 |
text))
|
84 |
|
@@ -88,10 +90,10 @@ def sequence_to_classify(text, labels):
|
|
88 |
lang = detect_lang(text)
|
89 |
if lang == 'en':
|
90 |
model = model_en
|
91 |
-
hypothesis_template = "
|
92 |
else:
|
93 |
model = model_multi
|
94 |
-
hypothesis_template = "{}
|
95 |
|
96 |
labels = [hypothesis_template.format(label) for label in labels.split(";;")]
|
97 |
|
|
|
1 |
import datetime
|
2 |
import gradio as gr
|
3 |
+
from huggingface_hub import hf_hub_download
|
4 |
import fasttext, torch, clip
|
5 |
from sentence_transformers import SentenceTransformer, util
|
6 |
|
7 |
model_en, _ = clip.load("ViT-B/32")
|
8 |
model_multi = SentenceTransformer("sentence-transformers/clip-ViT-B-32-multilingual-v1")
|
9 |
|
10 |
+
fasttext_model = fasttext.load_model(hf_hub_download("julien-c/fasttext-language-id", "lid.176.bin"))
|
11 |
+
|
12 |
def prep_examples():
|
13 |
example_text1 = "Coronavirus disease (COVID-19) is an infectious disease caused by the SARS-CoV-2 virus. Most \
|
14 |
people who fall sick with COVID-19 will experience mild to moderate symptoms and recover without special treatment. \
|
|
|
80 |
seq_lang = fasttext_model.predict(text, k=1)[0][0].split("__label__")[1]
|
81 |
except:
|
82 |
print("Language detection failed!",
|
83 |
+
"Date:{}, Sequence: {}".format(
|
84 |
str(datetime.datetime.now()),
|
85 |
text))
|
86 |
|
|
|
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 |
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
torch
|
2 |
sentence-transformers
|
3 |
git+https://github.com/openai/CLIP.git
|
4 |
-
|
5 |
fasttext
|
|
|
1 |
torch
|
2 |
sentence-transformers
|
3 |
git+https://github.com/openai/CLIP.git
|
4 |
+
huggingface_hub
|
5 |
fasttext
|