geethareddy commited on
Commit
575b90c
·
verified ·
1 Parent(s): 974001b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -35
app.py CHANGED
@@ -1,40 +1,72 @@
1
- from flask import Flask, request, jsonify
2
- from transformers import pipeline
 
3
  import os
4
 
5
- app = Flask(__name__)
 
6
 
7
- # Load ASR model
8
- asr_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-small")
9
-
10
- # Store user details
11
  user_data = {"name": "", "email": ""}
12
 
13
- @app.route("/voice_input", methods=["POST"])
14
- def voice_input():
15
- if "audio" not in request.files:
16
- return jsonify({"error": "No audio file received"}), 400
17
-
18
- file = request.files["audio"]
19
- file_path = "temp.wav"
20
- file.save(file_path)
21
-
22
- try:
23
- # Convert Speech to Text
24
- text = asr_pipeline(file_path)["text"]
25
-
26
- # Store name or email based on input
27
- if user_data["name"] == "":
28
- user_data["name"] = text
29
- return jsonify({"message": f"Name recorded: {text}"})
30
- elif user_data["email"] == "":
31
- user_data["email"] = text
32
- return jsonify({"message": f"Email recorded: {text}"})
33
-
34
- return jsonify({"message": "All details recorded", "data": user_data})
35
-
36
- except Exception as e:
37
- return jsonify({"error": str(e)}), 500
38
-
39
- if __name__ == "__main__":
40
- app.run(debug=True, host="0.0.0.0", port=5000)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import whisper
3
+ import time
4
  import os
5
 
6
+ # Load Whisper ASR Model
7
+ model = whisper.load_model("base")
8
 
9
+ # Store User Data
 
 
 
10
  user_data = {"name": "", "email": ""}
11
 
12
+ # Function to Play Welcome Message
13
+ def welcome_message():
14
+ return "Welcome to Biryani Hub. Tell me your name."
15
+
16
+ # Function to Capture Name
17
+ def capture_name(audio):
18
+ global user_data
19
+ if audio is None:
20
+ return "No audio detected. Please try again."
21
+
22
+ # Save the audio
23
+ audio_path = "name.wav"
24
+ audio.export(audio_path, format="wav")
25
+
26
+ # Convert Speech to Text
27
+ result = model.transcribe(audio_path)
28
+ user_data["name"] = result["text"]
29
+
30
+ return f"Hello, {user_data['name']}! Please provide your email address."
31
+
32
+ # Function to Capture Email
33
+ def capture_email(audio):
34
+ global user_data
35
+ if audio is None:
36
+ return "No audio detected. Please try again."
37
+
38
+ # Save the audio
39
+ audio_path = "email.wav"
40
+ audio.export(audio_path, format="wav")
41
+
42
+ # Convert Speech to Text
43
+ result = model.transcribe(audio_path)
44
+ user_data["email"] = result["text"]
45
+
46
+ return f"Thank you, {user_data['name']}! We have saved your email: {user_data['email']}."
47
+
48
+ # Create Gradio UI
49
+ with gr.Blocks() as demo:
50
+ gr.Markdown("# 🎙️ Voice-Enabled Restaurant Menu - Biryani Hub")
51
+
52
+ # Welcome Message
53
+ welcome = gr.Textbox(value=welcome_message(), interactive=False)
54
+
55
+ # Step 1: Capture Name
56
+ gr.Markdown("### 🗣️ Step 1: Say Your Name")
57
+ name_input = gr.Audio(source="microphone", type="file")
58
+ name_output = gr.Textbox()
59
+ name_button = gr.Button("Submit Name")
60
+
61
+ # Step 2: Capture Email
62
+ gr.Markdown("### 📧 Step 2: Say Your Email")
63
+ email_input = gr.Audio(source="microphone", type="file")
64
+ email_output = gr.Textbox()
65
+ email_button = gr.Button("Submit Email")
66
+
67
+ # Capture Name and Email
68
+ name_button.click(capture_name, inputs=name_input, outputs=name_output)
69
+ email_button.click(capture_email, inputs=email_input, outputs=email_output)
70
+
71
+ # Launch the App
72
+ demo.launch()