Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,24 @@
|
|
1 |
-
from flask import Flask, request, render_template_string, jsonify
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import torch
|
|
|
4 |
|
5 |
|
6 |
# Define the Flask app
|
7 |
flask_app = Flask(__name__)
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
model.eval() # Set the model to evaluation mode
|
14 |
|
15 |
def classify_sentiment(text):
|
|
|
1 |
+
from flask import Flask, request, render_template_string, jsonify, send_from_directory
|
2 |
+
import requests
|
3 |
+
import pandas as pd
|
4 |
+
import re
|
5 |
+
import time
|
6 |
+
from random import randint, choice
|
7 |
+
import os
|
8 |
+
from transformers import XLMRobertaForSequenceClassification, XLMRobertaTokenizer
|
9 |
+
from peft import PeftModel, PeftConfig # Ensure peft library is installed
|
10 |
import torch
|
11 |
+
from collections import defaultdict
|
12 |
|
13 |
|
14 |
# Define the Flask app
|
15 |
flask_app = Flask(__name__)
|
16 |
|
17 |
+
Load the base XLM-RoBERTa model with the correct number of labels (3 labels for classification)
|
18 |
+
tokenizer = XLMRobertaTokenizer.from_pretrained("letijo03/lora-adapter-32",use_fast=True, trust_remote_code=True)
|
19 |
+
base_model = XLMRobertaForSequenceClassification.from_pretrained("xlm-roberta-base", num_labels=3)
|
20 |
+
config = PeftConfig.from_pretrained("letijo03/lora-adapter-32")
|
21 |
+
model = PeftModel.from_pretrained(base_model, "letijo03/lora-adapter-32")
|
22 |
model.eval() # Set the model to evaluation mode
|
23 |
|
24 |
def classify_sentiment(text):
|