Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,9 @@ import time
|
|
3 |
import logging
|
4 |
import json
|
5 |
import requests
|
6 |
-
import torch
|
7 |
from flask import Flask, render_template, request, jsonify, session
|
8 |
from flask_session import Session
|
9 |
from simple_salesforce import Salesforce
|
10 |
-
from transformers import pipeline, AutoConfig
|
11 |
from gtts import gTTS
|
12 |
from pydub import AudioSegment
|
13 |
from pydub.silence import detect_nonsilent
|
@@ -30,11 +28,6 @@ try:
|
|
30 |
except Exception as e:
|
31 |
print(f"❌ Failed to connect to Salesforce: {str(e)}")
|
32 |
|
33 |
-
# Whisper ASR Configuration
|
34 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
35 |
-
config = AutoConfig.from_pretrained("openai/whisper-small")
|
36 |
-
config.update({"timeout": 60})
|
37 |
-
|
38 |
# Voice prompts
|
39 |
prompts = {
|
40 |
"welcome": "Welcome to Biryani Hub.",
|
@@ -146,7 +139,7 @@ def transcribe():
|
|
146 |
if is_silent_audio(output_audio_path):
|
147 |
return jsonify({"error": "No speech detected. Please try again."}), 400
|
148 |
|
149 |
-
result = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if torch.cuda.is_available() else -1
|
150 |
transcribed_text = result(output_audio_path)["text"].strip().capitalize()
|
151 |
|
152 |
return jsonify({"text": transcribed_text})
|
|
|
3 |
import logging
|
4 |
import json
|
5 |
import requests
|
|
|
6 |
from flask import Flask, render_template, request, jsonify, session
|
7 |
from flask_session import Session
|
8 |
from simple_salesforce import Salesforce
|
|
|
9 |
from gtts import gTTS
|
10 |
from pydub import AudioSegment
|
11 |
from pydub.silence import detect_nonsilent
|
|
|
28 |
except Exception as e:
|
29 |
print(f"❌ Failed to connect to Salesforce: {str(e)}")
|
30 |
|
|
|
|
|
|
|
|
|
|
|
31 |
# Voice prompts
|
32 |
prompts = {
|
33 |
"welcome": "Welcome to Biryani Hub.",
|
|
|
139 |
if is_silent_audio(output_audio_path):
|
140 |
return jsonify({"error": "No speech detected. Please try again."}), 400
|
141 |
|
142 |
+
result = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if torch.cuda.is_available() else -1)
|
143 |
transcribed_text = result(output_audio_path)["text"].strip().capitalize()
|
144 |
|
145 |
return jsonify({"text": transcribed_text})
|