kaushikbar commited on
Commit
38dd981
1 Parent(s): a0edd36
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +182 -0
  3. requirements.txt +6 -0
README.md CHANGED
@@ -10,4 +10,4 @@ pinned: false
10
  license: other
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
10
  license: other
11
  ---
12
 
13
+
app.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import gradio as gr
3
+ from huggingface_hub import hf_hub_download
4
+ from langdetect import detect, DetectorFactory, detect_langs
5
+ import fasttext
6
+ from transformers import pipeline
7
+
8
+ models = {'en': 'Narsil/deberta-large-mnli-zero-cls', # English
9
+ #'es': 'Recognai/zeroshot_selectra_medium', # Spanish
10
+ #'it': 'joeddav/xlm-roberta-large-xnli', # Italian
11
+ #'ru': 'DeepPavlov/xlm-roberta-large-en-ru-mnli', # Russian
12
+ #'tr': 'vicgalle/xlm-roberta-large-xnli-anli', # Turkish
13
+ #'no': 'NbAiLab/nb-bert-base-mnli', # Norsk
14
+ 'de': 'Sahajtomar/German_Zeroshot'} # German
15
+
16
+ hypothesis_templates = {'en': 'This example is {}.', # English
17
+ #'es': 'Este ejemplo es {}.', # Spanish
18
+ #'it': 'Questo esempio è {}.', # Italian
19
+ #'ru': 'Этот пример {}.', # Russian
20
+ #'tr': 'Bu örnek {}.', # Turkish
21
+ #'no': 'Dette eksempelet er {}.', # Norsk
22
+ 'de': 'Dieses beispiel ist {}.'} # German
23
+
24
+ classifiers = {'en': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['en'],
25
+ model=models['en']),
26
+ #'es': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['es'],
27
+ # model=models['es']),
28
+ #'it': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['it'],
29
+ # model=models['it']),
30
+ #'ru': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['ru'],
31
+ # model=models['ru']),
32
+ #'tr': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['tr'],
33
+ # model=models['tr']),
34
+ #'no': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['no'],
35
+ # model=models['no']),
36
+ 'de': pipeline("zero-shot-classification", hypothesis_template=hypothesis_templates['de'],
37
+ model=models['de'])}
38
+
39
+ fasttext_model = fasttext.load_model(hf_hub_download("julien-c/fasttext-language-id", "lid.176.bin"))
40
+
41
+ def prep_examples():
42
+ example_text1 = "The tangy feel in my mouth was a different experience altogether."
43
+ example_labels1 = "Taste;;Smell;;Delivery;;Packaging;;Availability"
44
+
45
+ example_text2 = "The aroma was not quite my type."
46
+ example_labels2 = "Taste;;Smell;;Delivery;;Packaging;;Availability"
47
+
48
+ example_text3 = "The chocolates came in an attractive orange box."
49
+ example_labels3 = "Taste;;Smell;;Delivery;;Packaging;;Availability"
50
+
51
+ example_text4 = "I can barely find this product in any store near where I stay."
52
+ example_labels4 = "This product has availability issues.;;Stores do not stock this product.;;I live in a remote place."
53
+
54
+ example_text5 = "I can barely find the products I love in the stores anywhere in this deserted place where I moved in few days back."
55
+ example_labels5 = "This product has availability issues.;;Stores do not stock this product.;;I live in a remote place."
56
+
57
+ example_text6 = "RATIONALE: The ability of nicotine to suppress body weight is cited as a factor impacting smoking initiation and the failure to quit. Self-administered nicotine in male rats suppresses weight independent of food intake, suggesting that nicotine increases energy expenditure. OBJECTIVE: The current experiment evaluated the impact of self-administered nicotine on metabolism in rats using indirect calorimetry and body composition analysis. METHODS: Adult male rats with ad libitum access to powdered standard rodent chow self-administered intravenous infusions of nicotine (60 μg/kg/infusion or saline control) in daily 1-h sessions in the last hour of the light cycle. Indirect calorimetry measured respiratory exchange ratio (RER), energy expenditure, motor activity, and food and water consumption for 22.5 h between select self-administration sessions. RESULTS: Self-administered nicotine suppressed weight gain and reduced the percent of body fat without altering the percent of lean mass, as measured by Echo MRI. Nicotine reduced RER, indicating increased fat utilization; this effect was observed prior to weight suppression. Moreover, nicotine intake did not affect motor activity or energy expenditure. Daily food intake was not altered by nicotine self-administration; however, a trend in suppression of meal size, a transient suppression of water intake, and an increase in meal frequency was observed. CONCLUSION: These data provide evidence that self-administered nicotine suppresses body weight via increased fat metabolism, independent of significant changes in feeding, activity, or energy expenditure. (Rupprecht et al. 2018)"
58
+ example_labels6 = "Metabolism/metabolites;;Exposure;;Repeated dose toxicity;;Single dose toxicity;;distribution and excretion;;Absorption"
59
+
60
+ example_text7 = "BACKGROUND AND PURPOSE: Tobacco smoke contains many classes of carcinogens and although nicotine is unable to initiate tumourigenesis in humans and rodents, it promotes tumour growth and metastasis in lung tumours by acting on neuronal nicotinic ACh receptors (nAChRs). The aim of this study was to identify molecularly, biochemically and pharmacologically which nAChR subtypes are expressed and functionally activated by nicotine in lung cancer cell lines. EXPERIMENTAL APPROACH: We used A549 and H1975 adenocarcinoma cell lines derived from lung tumours to test the in vitro effects of nicotine, and nAChR subtype-specific peptides and compounds. KEY RESULTS: The two adenocarcinoma cell lines express distinctive nAChR subtypes, and this affects their nicotine-induced proliferation. In A549 cells, nAChRs containing the α7 or α9 subunits not only regulate nicotine-induced cell proliferation but also the activation of the Akt and ERK pathways. Blocking these nAChRs by means of subtype-specific peptides, or silencing their expression by means of subunit-specific siRNAs, abolishes nicotine-induced proliferation and signalling. Moreover, we found that the α7 antagonist MG624 also acts on α9-α10 nAChRs, blocks the effects of nicotine on A549 cells and has dose-dependent cytotoxic activity. CONCLUSIONS AND IMPLICATIONS: These results highlight the pathophysiological role of α7- and α9-containing receptors in promoting non-small cell lung carcinoma cell growth and intracellular signalling and provide a framework for the development of new drugs that specifically target the receptors expressed in lung tumours. (Mucchietto et al. 2018)."
61
+ example_labels7 = "Metabolism/metabolites;;Exposure;;Repeated dose toxicity;;Single dose toxicity;;Carcinogenicity;;Cytotoxicity;;distribution and excretion;;Absorption"
62
+
63
+ example_text8 = "It is well-documented that nicotine, the main active ingredient in cigarettes, results in endothelial cell injury in numerous diseases. However, whether nicotine plays a crucial role in endothelial cell injury in diabetes and the exact molecular mechanism that mediates this process have not been fully elucidated. The current study aimed to investigate the effects of nicotine on endothelial cell injury in diabetes and the specific molecular mechanism by which it plays a role. Human umbilical vein endothelial cells (HUVECs) were incubated in HG/HF media and treated with nicotine, PYR-41 (a selective ubiquitin E1 inhibitor), Akt-overexpressing adenovirus, or TTC3 and MUL1 shRNA adenovirus. Cell viability was subsequently detected by the CCK8 assay, and apoptosis was examined by caspase-3 cleavage and activity analysis. Compared to the HG/HF incubated group, nicotine incubation significantly decreased cell survival and increased apoptosis. Moreover, nicotine induced Akt degradation via UPS, and Akt overexpression blocked nicotine-induced apoptosis in HUVECs cultured in HG/HF media. Furthermore, the TTC3 and MUL1 shRNA adenovirus dramatically decreased the Akt ubiquitination and apoptosis induced by nicotine. These results indicate that nicotine-induced Akt ubiquitination and degradation occurs through TTC3 and MUL1 and results in a dramatic increase in apoptosis in HUVECs cultured in HG/HF media. (Cao et al. 2018)."
64
+ example_labels8 = "Metabolism/metabolites;;Exposure;;Repeated dose toxicity;;Single dose toxicity;;Carcinogenicity;;Cytotoxicity;;distribution and excretion;;Absorption"
65
+
66
+ example_text9 = "Elephants are"
67
+ example_labels9 = "big;;small;;strong;;fast;;carnivorous"
68
+
69
+ example_text10 = "Do dogs really make better pets than cats or hamsters?"
70
+ example_labels10 = "kittens;;hamsters;;cats;;dogs"
71
+
72
+ example_text11 = "He is hungry."
73
+ example_labels11 = "Positive;;Negative"
74
+
75
+ example_text12 = "He is hungry to learn."
76
+ example_labels12 = "Positive;;Negative"
77
+
78
+ example_text13 = "Gogh was playing with his brush."
79
+ example_labels13 = "Painting;;Amusement;;Sport"
80
+
81
+ example_text14 = "He was playing with his brush."
82
+ example_labels14 = "Painting;;Amusement;;Sport"
83
+
84
+ example_text15 = "Googh was sitting by the window. He was playing with his brush."
85
+ example_labels15 = "Painting;;Amusement;;Sport"
86
+
87
+ example_text16 = "Microsoft has turned itself around."
88
+ example_labels16 = "Under the leadership of Nadella;;Despite the leadership of Nadella;;And Nadella had nothing to do with it;;Under the leadership of Pichai"
89
+
90
+ examples = [
91
+ [example_text1, example_labels1],
92
+ [example_text2, example_labels2],
93
+ [example_text3, example_labels3],
94
+ [example_text4, example_labels4],
95
+ [example_text5, example_labels5],
96
+ [example_text6, example_labels6],
97
+ [example_text7, example_labels7],
98
+ [example_text8, example_labels8],
99
+ [example_text9, example_labels9],
100
+ [example_text10, example_labels10],
101
+ [example_text11, example_labels11],,
102
+ [example_text12, example_labels12]
103
+ [example_text13, example_labels13],
104
+ [example_text14, example_labels14],
105
+ [example_text15, example_labels15],
106
+ [example_text16, example_labels16]]
107
+
108
+ return examples
109
+
110
+ def detect_lang(sequence, labels):
111
+ DetectorFactory.seed = 0
112
+ seq_lang = 'en'
113
+
114
+ sequence = sequence.replace('\n', ' ')
115
+
116
+ try:
117
+ #seq_lang = detect(sequence)
118
+ #lbl_lang = detect(labels)
119
+ seq_lang = fasttext_model.predict(sequence, k=1)[0][0].split("__label__")[1]
120
+ lbl_lang = fasttext_model.predict(labels, k=1)[0][0].split("__label__")[1]
121
+ except:
122
+ print("Language detection failed!",
123
+ "Date:{}, Sequence:{}, Labels:{}".format(
124
+ str(datetime.datetime.now()),
125
+ labels))
126
+
127
+ if seq_lang != lbl_lang:
128
+ print("Different languages detected for sequence and labels!",
129
+ "Date:{}, Sequence:{}, Labels:{}, Sequence Language:{}, Label Language:{}".format(
130
+ str(datetime.datetime.now()),
131
+ sequence,
132
+ labels,
133
+ seq_lang,
134
+ lbl_lang))
135
+
136
+ if seq_lang in models:
137
+ print("Sequence Language detected.",
138
+ "Date:{}, Sequence:{}, Sequence Language:{}".format(
139
+ str(datetime.datetime.now()),
140
+ sequence,
141
+ seq_lang))
142
+ else:
143
+ print("Language not supported. Defaulting to English!",
144
+ "Date:{}, Sequence:{}, Sequence Language:{}".format(
145
+ str(datetime.datetime.now()),
146
+ sequence,
147
+ seq_lang))
148
+ seq_lang = 'en'
149
+
150
+ return seq_lang
151
+
152
+ def sequence_to_classify(sequence, labels):
153
+ classifier = classifiers[detect_lang(sequence, labels)]
154
+
155
+ label_clean = str(labels).split(";;")
156
+ response = classifier(sequence, label_clean, multi_label=True)
157
+
158
+ predicted_labels = response['labels']
159
+ predicted_scores = response['scores']
160
+ clean_output = {idx: float(predicted_scores.pop(0)) for idx in predicted_labels}
161
+ print("Date:{}, Sequence:{}, Labels: {}".format(
162
+ str(datetime.datetime.now()),
163
+ sequence,
164
+ predicted_labels))
165
+
166
+ return clean_output
167
+
168
+ iface = gr.Interface(
169
+ title="MARS Demo",
170
+ description="Off-the-shelf NLP classifier.",
171
+ fn=sequence_to_classify,
172
+ inputs=[gr.inputs.Textbox(lines=10,
173
+ label="Please enter the text you would like to classify...",
174
+ placeholder="Text here..."),
175
+ gr.inputs.Textbox(lines=2,
176
+ label="Please enter the candidate labels (separated by 2 consecutive semicolons)...",
177
+ placeholder="Labels here separated by ;;")],
178
+ outputs=gr.outputs.Label(num_top_classes=5),
179
+ #interpretation="default",
180
+ examples=prep_examples())
181
+
182
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ transformers
2
+ sentence-transformers
3
+ torch
4
+ langdetect
5
+ fasttext
6
+