shobhit654321-7 commited on
Commit
3782556
1 Parent(s): 42a04b5

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import speech_recognition as sr
3
+
4
+ # Function to recognize speech
5
+ def recognize_speech():
6
+ recognizer = sr.Recognizer()
7
+ with sr.Microphone() as source:
8
+ st.write("Listening...")
9
+ recognizer.adjust_for_ambient_noise(source, duration=1)
10
+ audio = recognizer.listen(source)
11
+
12
+ try:
13
+ st.write("Recognizing...")
14
+ text = recognizer.recognize_google(audio).lower()
15
+ return text
16
+ except sr.UnknownValueError:
17
+ st.write("Sorry, I couldn't understand what you said.")
18
+ except sr.RequestError as e:
19
+ st.write(f"Could not request results; {e}")
20
+
21
+ # Function to provide answers based on user's query
22
+ def get_answer(question):
23
+ # Define a dictionary mapping questions to answers
24
+ answer_dict = {
25
+ "what is the capital of India?": "The capital of India is New Delhi.",
26
+ "what is the population of India?": "The population of India is approximately 1.3 billion.",
27
+ "what is the currency of India?": "The currency of India is the Indian Rupee (INR).",
28
+ # Add more questions and answers as needed
29
+ }
30
+ # Check if the question exists in the answer dictionary
31
+ if question in answer_dict:
32
+ return answer_dict[question]
33
+ else:
34
+ return "Sorry, I don't have an answer to that question."
35
+
36
+ # Main function
37
+ def main():
38
+ st.title("Indian States Information App")
39
+ st.write("Welcome to the Indian States Information App!")
40
+
41
+ button_counter = 0 # Counter for generating unique button keys
42
+
43
+ while True:
44
+ button_counter += 1
45
+ key = f"speak_button_{button_counter}"
46
+ st.write("Press the button and ask your question:")
47
+ command = st.button("Speak", key=key)
48
+
49
+ if command:
50
+ question = recognize_speech()
51
+ if question:
52
+ st.write("You asked:", question)
53
+ answer = get_answer(question)
54
+ st.write("Answer:", answer)
55
+
56
+ if __name__ == "__main__":
57
+ main()
58
+