Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -281,34 +281,47 @@ CORS(app)
|
|
| 281 |
def intents():
|
| 282 |
return jsonify({"intents" :list(set(df['intent'].dropna()))})
|
| 283 |
|
| 284 |
-
@app.route("/en_response", methods=["POST"])
|
| 285 |
-
def query_response():
|
| 286 |
-
data = request.get_json()
|
| 287 |
-
query = data.get("query", "")
|
| 288 |
-
# Get current time in seconds
|
| 289 |
-
if not query:
|
| 290 |
-
return jsonify({"error": "Query cannot be empty"}), 400
|
| 291 |
|
| 292 |
-
start = time.time()
|
| 293 |
-
# Assuming `generate_response` is a function that processes the query
|
| 294 |
-
response = generate_response(model, query)
|
| 295 |
-
end = time.time()
|
| 296 |
-
return jsonify({"english":(response),"response_time":(end-start)})
|
| 297 |
|
| 298 |
@app.route("/translate", methods=["POST"])
|
| 299 |
-
def
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
data = request.get_json()
|
| 302 |
query = data.get("query", "")
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
def clean_response(response):
|
| 305 |
return response.replace("<EOS>", "").replace("<SOS>", "").strip()
|
| 306 |
-
|
| 307 |
-
response=clean_response(response)
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
| 312 |
|
| 313 |
@app.route("/query", methods=["POST"])
|
| 314 |
def query_model():
|
|
|
|
| 281 |
def intents():
|
| 282 |
return jsonify({"intents" :list(set(df['intent'].dropna()))})
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
|
| 286 |
@app.route("/translate", methods=["POST"])
|
| 287 |
+
def translate_text():
|
| 288 |
+
data = request.get_json()
|
| 289 |
+
text = data.get("text", "")
|
| 290 |
+
if not text:
|
| 291 |
+
return jsonify({"error": "Text cannot be empty"}), 400
|
| 292 |
+
|
| 293 |
+
# First generate English response
|
| 294 |
+
english_response = text
|
| 295 |
+
start=time.time()
|
| 296 |
+
# Then translate to Telugu
|
| 297 |
+
telugu_response = translate(model_telugu, english_response, en_vocab, te_vocab, te_inv_vocab)
|
| 298 |
+
end=time.time()
|
| 299 |
+
return jsonify({
|
| 300 |
+
"english": english_response,
|
| 301 |
+
"telugu": telugu_response,
|
| 302 |
+
"time": end-start
|
| 303 |
+
})
|
| 304 |
+
|
| 305 |
+
@app.route("/generate", methods=["POST"])
|
| 306 |
+
def generate_text():
|
| 307 |
data = request.get_json()
|
| 308 |
query = data.get("query", "")
|
| 309 |
+
|
| 310 |
+
if not query:
|
| 311 |
+
return jsonify({"error": "Query cannot be empty"}), 400
|
| 312 |
+
start=time.time()
|
| 313 |
+
response = generate_response(model, query)
|
| 314 |
+
end=time.time()
|
| 315 |
+
# Clean the response
|
| 316 |
def clean_response(response):
|
| 317 |
return response.replace("<EOS>", "").replace("<SOS>", "").strip()
|
| 318 |
+
|
| 319 |
+
response = clean_response(response)
|
| 320 |
+
|
| 321 |
+
return jsonify({
|
| 322 |
+
"response": response,
|
| 323 |
+
"time": end-start
|
| 324 |
+
})
|
| 325 |
|
| 326 |
@app.route("/query", methods=["POST"])
|
| 327 |
def query_model():
|