Spaces:
Sleeping
Sleeping
Commit
·
2465f17
1
Parent(s):
337a697
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,16 @@
|
|
| 1 |
from flask import Flask, jsonify, request, render_template
|
| 2 |
from transformers import AutoAdapterModel, AutoTokenizer, TextClassificationPipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# fusion_adapter = Repository(local_dir="fusion_adapter", clone_from="nehalelkaref/region_fusion")
|
| 11 |
|
| 12 |
-
|
| 13 |
-
# model.load_adapter("nehalelkaref/aoc4_adapter", set_active=True, with_head=False, source="hf")
|
| 14 |
-
# model.load_adapter("nehalelkaref/sarcasm_adapter", set_active=True, with_head=False, source="hf")
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# pipe = TextClassificationPipeline(tokenizer=tokenizer, model=model)
|
| 19 |
|
| 20 |
|
| 21 |
app = Flask(__name__)
|
|
@@ -26,8 +21,15 @@ def home():
|
|
| 26 |
|
| 27 |
@app.route('/classify', methods = ['POST'])
|
| 28 |
def classify():
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
app.run()
|
|
|
|
| 1 |
from flask import Flask, jsonify, request, render_template
|
| 2 |
from transformers import AutoAdapterModel, AutoTokenizer, TextClassificationPipeline
|
| 3 |
|
| 4 |
+
tokenizer = AutoTokenizer.from_pretrained("UBC-NLP/MARBERT")
|
| 5 |
+
model = AutoAdapterModel.from_pretrained("UBC-NLP/MARBERT")
|
| 6 |
|
| 7 |
+
model.load_adapter("nehalelkaref/aoc3_adapter", set_active=True, with_head=False, source="hf")
|
| 8 |
+
model.load_adapter("nehalelkaref/aoc4_adapter", set_active=True, with_head=False, source="hf")
|
| 9 |
+
model.load_adapter("nehalelkaref/sarcasm_adapter", set_active=True, with_head=False, source="hf")
|
|
|
|
| 10 |
|
| 11 |
+
model.load_adapter_fusion("nehalelkaref/region_fusion",with_head=True, set_active=True, source="hf")
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
pipe = TextClassificationPipeline(tokenizer=tokenizer, model=model)
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
app = Flask(__name__)
|
|
|
|
| 21 |
|
| 22 |
@app.route('/classify', methods = ['POST'])
|
| 23 |
def classify():
|
| 24 |
+
text = request.json['inputs']
|
| 25 |
+
|
| 26 |
+
prediction = pipe(text)
|
| 27 |
+
labels = {"LABEL_0":"GULF", "LABEL_1":"LEVANT","LABEL_2":"EGYPT"}
|
| 28 |
+
regions = []
|
| 29 |
+
for res in prediction:
|
| 30 |
+
regions.append(labels[res['label']])
|
| 31 |
+
|
| 32 |
+
return render_template('prediction.html', output=regions[0])
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
app.run()
|