vinay0123 commited on
Commit
79710ef
·
verified ·
1 Parent(s): 7f0a186

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -20
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
- return jsonify({"message": "hellooooooooo"})
 
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
- filename = f"speech_{uuid.uuid4().hex}.mp3"
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
- speech.save(filepath)
371
-
372
- # Automatically delete the file after sending
373
- @after_this_request
374
- def cleanup(response):
375
- try:
376
- os.remove(filepath)
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)