Spaces:
Runtime error
Runtime error
Commit
·
2a6bb6a
1
Parent(s):
20c986e
Update app.py
Browse files
app.py
CHANGED
|
@@ -138,7 +138,7 @@ def toxicityAnalys():
|
|
| 138 |
|
| 139 |
return {"status": "pass", "toxicity": predicted_sentiment}
|
| 140 |
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
| 141 |
-
@app.route('/analyzeText/api/v1/chitchat', methods=['
|
| 142 |
def chitchatRu():
|
| 143 |
try:
|
| 144 |
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or ""
|
|
@@ -146,15 +146,15 @@ def chitchatRu():
|
|
| 146 |
try: text = request.json.get('text') or ""
|
| 147 |
except: pass
|
| 148 |
|
| 149 |
-
if text == "":
|
| 150 |
-
|
| 151 |
-
inputs = chct_t(text, padding=True, truncation=True, return_tensors="pt")
|
| 152 |
|
|
|
|
| 153 |
generated_ids = chct_m.generate(input_ids=inputs)
|
| 154 |
answer = chct_t.decode(generated_ids[0], skip_special_tokens=True)
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
| 160 |
config = configFile()
|
|
|
|
| 138 |
|
| 139 |
return {"status": "pass", "toxicity": predicted_sentiment}
|
| 140 |
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
| 141 |
+
@app.route('/analyzeText/api/v1/chitchat', methods=['POST'])
|
| 142 |
def chitchatRu():
|
| 143 |
try:
|
| 144 |
text = request.form.get('text') or request.args.get('text') or request.values.get('text') or ""
|
|
|
|
| 146 |
try: text = request.json.get('text') or ""
|
| 147 |
except: pass
|
| 148 |
|
| 149 |
+
if text == "":
|
| 150 |
+
return {"status": "error", "details": {"error_code": 101, "error_details": "No text provided"}}, 400
|
|
|
|
| 151 |
|
| 152 |
+
inputs = chct_t.encode(text, padding=True, truncation=True, return_tensors="pt")
|
| 153 |
generated_ids = chct_m.generate(input_ids=inputs)
|
| 154 |
answer = chct_t.decode(generated_ids[0], skip_special_tokens=True)
|
| 155 |
+
return {"status": "pass", "answer": answer}, 200
|
| 156 |
+
except Exception as e:
|
| 157 |
+
return {"status": "error", "details": {"error_code": 123, "error_details": str(e).replace("\n", " | ")}}, 400
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
| 160 |
config = configFile()
|