Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
|
| 2 |
import textwrap
|
| 3 |
import torch
|
|
|
|
| 4 |
import torch.nn as nn
|
| 5 |
import torch.optim as optim
|
| 6 |
import spacy
|
|
@@ -277,9 +278,11 @@ model_telugu.eval()
|
|
| 277 |
app=Flask(__name__)
|
| 278 |
CORS(app)
|
| 279 |
|
|
|
|
| 280 |
@app.route("/")
|
| 281 |
def home():
|
| 282 |
-
|
|
|
|
| 283 |
|
| 284 |
|
| 285 |
@app.route("/intent")
|
|
@@ -355,27 +358,17 @@ def query_model():
|
|
| 355 |
def get_audio():
|
| 356 |
data = request.get_json()
|
| 357 |
text = data.get("text")
|
|
|
|
| 358 |
|
| 359 |
-
# text=audio_telugu_response
|
| 360 |
if not text:
|
| 361 |
return jsonify({"error": "No Response To convert to speech"}), 400
|
| 362 |
|
| 363 |
-
|
| 364 |
-
filepath = os.path.join("audio_temp", filename)
|
| 365 |
-
|
| 366 |
-
os.makedirs("audio_temp", exist_ok=True)
|
| 367 |
-
|
| 368 |
-
# Convert text to Telugu speech
|
| 369 |
speech = gTTS(text=text, lang="te")
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
except Exception as e:
|
| 378 |
-
print(f"Cleanup error: {e}")
|
| 379 |
-
return response
|
| 380 |
-
|
| 381 |
-
return send_file(filepath, mimetype="audio/mpeg", as_attachment=False)
|
|
|
|
| 1 |
|
| 2 |
import textwrap
|
| 3 |
import torch
|
| 4 |
+
from datetime import datetime
|
| 5 |
import torch.nn as nn
|
| 6 |
import torch.optim as optim
|
| 7 |
import spacy
|
|
|
|
| 278 |
app=Flask(__name__)
|
| 279 |
CORS(app)
|
| 280 |
|
| 281 |
+
|
| 282 |
@app.route("/")
|
| 283 |
def home():
|
| 284 |
+
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 285 |
+
return jsonify({"message": f"Welcome to TRAVIS API, Time : {current_time}"})
|
| 286 |
|
| 287 |
|
| 288 |
@app.route("/intent")
|
|
|
|
| 358 |
def get_audio():
|
| 359 |
data = request.get_json()
|
| 360 |
text = data.get("text")
|
| 361 |
+
start_te = time.time()
|
| 362 |
|
|
|
|
| 363 |
if not text:
|
| 364 |
return jsonify({"error": "No Response To convert to speech"}), 400
|
| 365 |
|
| 366 |
+
# Convert text to Telugu speech using in-memory file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
speech = gTTS(text=text, lang="te")
|
| 368 |
+
audio_io = io.BytesIO()
|
| 369 |
+
speech.write_to_fp(audio_io)
|
| 370 |
+
audio_io.seek(0)
|
| 371 |
+
end_te = time.time()
|
| 372 |
+
print("telugu_time":(end_te-start_te))
|
| 373 |
+
|
| 374 |
+
return send_file(audio_io, mimetype="audio/mpeg", as_attachment=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|