Spaces:
Sleeping
Sleeping
Commit
·
8357c1f
1
Parent(s):
580f33f
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification, Auto
|
|
11 |
|
12 |
#initing
|
13 |
app = Flask(__name__)
|
14 |
-
VERSION = '1.0
|
15 |
app.config['JSON_AS_ASCII'] = False
|
16 |
limiter = Limiter(app=app, key_func=get_remote_address, default_limits=["5/minute"], storage_uri="memory://",)
|
17 |
|
@@ -101,7 +101,7 @@ chct_t, chct_m = AutoTokenizer.from_pretrained("cointegrated/rut5-small-chitchat
|
|
101 |
@app.route('/analyzeText/api/v1/sentiment', methods=['GET', 'POST'])
|
102 |
def sentimentAnalys():
|
103 |
try:
|
104 |
-
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or ""
|
105 |
if text == "": return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }}
|
106 |
|
107 |
inputs = sa_t(text, return_tensors="pt")
|
@@ -117,8 +117,8 @@ def sentimentAnalys():
|
|
117 |
@app.route('/analyzeText/api/v1/toxicity', methods=['GET', 'POST'])
|
118 |
def toxicityAnalys():
|
119 |
try:
|
120 |
-
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or ""
|
121 |
-
if text == "": return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }}
|
122 |
|
123 |
inputs = tc_t(text, return_tensors="pt")
|
124 |
|
@@ -129,12 +129,12 @@ def toxicityAnalys():
|
|
129 |
predicted_sentiment = True if str(tc_m.config.id2label[predicted_class]) == "LABEL_1" else False
|
130 |
|
131 |
return {"status": "pass", "toxicity": predicted_sentiment}
|
132 |
-
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }}
|
133 |
@app.route('/analyzeText/api/v1/chitchat', methods=['GET', 'POST'])
|
134 |
def chitchatRu():
|
135 |
try:
|
136 |
-
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or ""
|
137 |
-
if text == "": return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }}
|
138 |
|
139 |
inputs = chct_t(text, padding=True, truncation=True, return_tensors="pt")
|
140 |
|
@@ -142,7 +142,7 @@ def chitchatRu():
|
|
142 |
answer = chct_t.decode(generated_ids[0], skip_special_tokens=True)
|
143 |
|
144 |
return {"status": "pass", "answer": answer}
|
145 |
-
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }}
|
146 |
|
147 |
if __name__ == "__main__":
|
148 |
config = configFile()
|
|
|
11 |
|
12 |
#initing
|
13 |
app = Flask(__name__)
|
14 |
+
VERSION = '1.0 build114'
|
15 |
app.config['JSON_AS_ASCII'] = False
|
16 |
limiter = Limiter(app=app, key_func=get_remote_address, default_limits=["5/minute"], storage_uri="memory://",)
|
17 |
|
|
|
101 |
@app.route('/analyzeText/api/v1/sentiment', methods=['GET', 'POST'])
|
102 |
def sentimentAnalys():
|
103 |
try:
|
104 |
+
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or request.json.get('text') or ""
|
105 |
if text == "": return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }}
|
106 |
|
107 |
inputs = sa_t(text, return_tensors="pt")
|
|
|
117 |
@app.route('/analyzeText/api/v1/toxicity', methods=['GET', 'POST'])
|
118 |
def toxicityAnalys():
|
119 |
try:
|
120 |
+
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or request.json.get('text') or ""
|
121 |
+
if text == "": return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }} , 400
|
122 |
|
123 |
inputs = tc_t(text, return_tensors="pt")
|
124 |
|
|
|
129 |
predicted_sentiment = True if str(tc_m.config.id2label[predicted_class]) == "LABEL_1" else False
|
130 |
|
131 |
return {"status": "pass", "toxicity": predicted_sentiment}
|
132 |
+
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
133 |
@app.route('/analyzeText/api/v1/chitchat', methods=['GET', 'POST'])
|
134 |
def chitchatRu():
|
135 |
try:
|
136 |
+
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or request.json.get('text') or ""
|
137 |
+
if text == "": return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }} , 400
|
138 |
|
139 |
inputs = chct_t(text, padding=True, truncation=True, return_tensors="pt")
|
140 |
|
|
|
142 |
answer = chct_t.decode(generated_ids[0], skip_special_tokens=True)
|
143 |
|
144 |
return {"status": "pass", "answer": answer}
|
145 |
+
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
146 |
|
147 |
if __name__ == "__main__":
|
148 |
config = configFile()
|