Spaces:
Runtime error
Runtime error
File size: 1,227 Bytes
26ce2b9 c6d903d 2465f17 c6d903d 2465f17 bae20b2 2465f17 c6d903d 2465f17 c6d903d 4a93af1 ed909e7 10d7087 5d35835 89fe9f7 7ff0c05 2465f17 e616e89 2465f17 7ff0c05 ad0751b 6ec95e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from flask import Flask, jsonify, request, render_template
from transformers import AutoAdapterModel, AutoTokenizer, TextClassificationPipeline
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("nehalelkaref/region_fusion",with_head=True, set_active=True, source="hf")
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.json['inputs']
prediction = pipe(text)
labels = {"LABEL_0":"GULF", "LABEL_1":"LEVANT","LABEL_2":"EGYPT"}
regions = []
for res in prediction:
regions.append(labels[res['label']])
return render_template('prediction.html', output=regions[0])
if __name__ == "__main__":
app.run() |