nehalelkaref commited on
Commit
2465f17
1 Parent(s): 337a697

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
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
- # tokenizer = AutoTokenizer.from_pretrained("UBC-NLP/MARBERT")
5
- # model = AutoAdapterModel.from_pretrained("UBC-NLP/MARBERT")
6
 
7
- # sarcasm_adapter = Repository(local_dir="sarcasm_adapter", clone_from="nehalelkaref/sarcasm_adapter")
8
- # aoc3_adapter = Repository(local_dir="aoc3_adapter", clone_from="nehalelkaref/aoc3_adapter")
9
- # aoc4_adapter = Repository(local_dir="aoc4_adapter", clone_from="nehalelkaref/aoc4_adapter")
10
- # fusion_adapter = Repository(local_dir="fusion_adapter", clone_from="nehalelkaref/region_fusion")
11
 
12
- # model.load_adapter("nehalelkaref/aoc3_adapter", set_active=True, with_head=False, source="hf")
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
- # model.load_adapter_fusion("nehalelkaref/region_fusion",with_head=True, set_active=True, source="hf")
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
- output = "TA DA!"
30
- return render_template('prediction.html', output=output)
 
 
 
 
 
 
 
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()