Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from transformers import AutoConfig
|
|
10 |
import time
|
11 |
from waitress import serve
|
12 |
from simple_salesforce import Salesforce
|
13 |
-
import requests
|
14 |
|
15 |
app = Flask(__name__, template_folder="templates")
|
16 |
app.secret_key = os.urandom(24)
|
@@ -22,42 +22,6 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
22 |
config = AutoConfig.from_pretrained("openai/whisper-small")
|
23 |
config.update({"timeout": 60}) # Set timeout to 60 seconds
|
24 |
|
25 |
-
# Function to generate audio prompts
|
26 |
-
def generate_audio_prompt(text, filename):
|
27 |
-
try:
|
28 |
-
tts = gTTS(text)
|
29 |
-
tts.save(os.path.join("static", filename))
|
30 |
-
except Exception as e:
|
31 |
-
print(f"Error: {e}")
|
32 |
-
time.sleep(5) # Wait before retrying
|
33 |
-
generate_audio_prompt(text, filename)
|
34 |
-
|
35 |
-
# Generate required voice prompts
|
36 |
-
prompts = {
|
37 |
-
"welcome": "Welcome to Biryani Hub.",
|
38 |
-
"ask_name": "Tell me your name.",
|
39 |
-
"ask_email": "Please provide your email address.",
|
40 |
-
"thank_you": "Thank you for registration."
|
41 |
-
}
|
42 |
-
|
43 |
-
for key, text in prompts.items():
|
44 |
-
generate_audio_prompt(text, f"{key}.mp3")
|
45 |
-
|
46 |
-
# Function to convert audio to WAV format
|
47 |
-
def convert_to_wav(input_path, output_path):
|
48 |
-
try:
|
49 |
-
audio = AudioSegment.from_file(input_path)
|
50 |
-
audio = audio.set_frame_rate(16000).set_channels(1) # Convert to 16kHz, mono
|
51 |
-
audio.export(output_path, format="wav")
|
52 |
-
except Exception as e:
|
53 |
-
raise Exception(f"Audio conversion failed: {str(e)}")
|
54 |
-
|
55 |
-
# Function to check if audio contains actual speech
|
56 |
-
def is_silent_audio(audio_path):
|
57 |
-
audio = AudioSegment.from_wav(audio_path)
|
58 |
-
nonsilent_parts = detect_nonsilent(audio, min_silence_len=500, silence_thresh=audio.dBFS-16)
|
59 |
-
return len(nonsilent_parts) == 0
|
60 |
-
|
61 |
# Salesforce connection details
|
62 |
try:
|
63 |
print("Attempting to connect to Salesforce...")
|
@@ -76,7 +40,7 @@ def index():
|
|
76 |
def dashboard():
|
77 |
return render_template("dashboard.html")
|
78 |
|
79 |
-
# ✅ MENU PAGE ROUTE
|
80 |
@app.route("/menu_page", methods=["GET"])
|
81 |
def menu_page():
|
82 |
try:
|
@@ -97,7 +61,6 @@ def menu_page():
|
|
97 |
except Exception as e:
|
98 |
return jsonify({"error": f"Failed to fetch menu: {str(e)}"}), 500
|
99 |
|
100 |
-
|
101 |
# ✅ STATIC IMAGES ROUTE
|
102 |
@app.route("/static/images/<path:filename>")
|
103 |
def static_images(filename):
|
|
|
10 |
import time
|
11 |
from waitress import serve
|
12 |
from simple_salesforce import Salesforce
|
13 |
+
import requests
|
14 |
|
15 |
app = Flask(__name__, template_folder="templates")
|
16 |
app.secret_key = os.urandom(24)
|
|
|
22 |
config = AutoConfig.from_pretrained("openai/whisper-small")
|
23 |
config.update({"timeout": 60}) # Set timeout to 60 seconds
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# Salesforce connection details
|
26 |
try:
|
27 |
print("Attempting to connect to Salesforce...")
|
|
|
40 |
def dashboard():
|
41 |
return render_template("dashboard.html")
|
42 |
|
43 |
+
# ✅ MENU PAGE ROUTE (NEWLY ADDED)
|
44 |
@app.route("/menu_page", methods=["GET"])
|
45 |
def menu_page():
|
46 |
try:
|
|
|
61 |
except Exception as e:
|
62 |
return jsonify({"error": f"Failed to fetch menu: {str(e)}"}), 500
|
63 |
|
|
|
64 |
# ✅ STATIC IMAGES ROUTE
|
65 |
@app.route("/static/images/<path:filename>")
|
66 |
def static_images(filename):
|