from flask import Flask, jsonify, request, render_template from transformers import AutoAdapterModel, AutoTokenizer, TextClassificationPipeline import numpy tokenizer = AutoTokenizer.from_pretrained("UBC-NLP/MARBERT") model = AutoAdapterModel.from_pretrained("UBC-NLP/MARBERT") model.load_adapter("nehalelkaref/aoc3_adapter", set_active=True, with_head=False, source="hf") model.load_adapter("nehalelkaref/aoc4_adapter", set_active=True, with_head=False, source="hf") model.load_adapter("nehalelkaref/sarcasm_adapter", set_active=True, with_head=False, source="hf") model.load_adapter_fusion("fusion/",with_head=True, set_active=True) pipe = TextClassificationPipeline(tokenizer=tokenizer, model=model) app = Flask(__name__) @app.route("/", methods=['GET']) def home(): return render_template('home.html') @app.route('/classify', methods = ['POST']) def classify(): text = request.form['comment'] print(text) prediction = pipe(text) labels = {"LABEL_0":"GULF", "LABEL_1":"LEVANT","LABEL_2":"EGYPT"} regions = [] for res in prediction: regions.append(labels[res['label']]) if(regions[0]=="GULF"): return render_template('gulf.html',output=regions[0]) if(regions[0]=="LEVANT"): return render_template('levant.html',output=regions[0]) if(regions[0]=="EGYPT"): return render_template('egypt.html',output=regions[0]) if __name__ == "__main__": app.run()