nailarais1 commited on
Commit
6c7fe6c
·
verified ·
1 Parent(s): 95cf5b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -80,20 +80,20 @@ def process_math(query):
80
  return f"Error: Unable to process the query. Please check the syntax. Error: {e}", None
81
 
82
  # Gradio interface function to handle the input
83
- def calculator(choice, text_input=None, audio=None):
84
- if choice == "voice":
85
- # Convert speech to text using CMU Sphinx from the microphone or uploaded audio
86
  query = voice_to_text_from_microphone(audio)
87
  if query.lower() == "sorry, i could not understand the audio.":
88
  return query, None
89
 
90
- print(f"Original Query (Voice): {query}")
91
 
92
  # Convert speech to math expression
93
  query = convert_speech_to_math(query)
94
  print(f"Converted Math Expression: {query}")
95
-
96
- elif choice == "text" and text_input:
97
  # If text input is provided directly
98
  query = text_input
99
  print(f"Original Query (Text): {query}")
@@ -108,21 +108,14 @@ def start_interface():
108
  interface = gr.Interface(
109
  fn=calculator,
110
  inputs=[
111
- gr.Radio(
112
- choices=["voice", "text"],
113
- label="Choose Input Type",
114
- type="value"
115
- ), # Option to select between voice and text input
116
  gr.Textbox(
117
- label="Or Type a Math Expression (Optional)",
118
- placeholder="Type your math expression here...",
119
- visible=False # Hide this for voice input, will be shown when text is selected
120
- ),
121
  gr.Audio(
122
- label="Upload an Audio File (Optional)",
123
- type="filepath",
124
- visible=False # Hide this for text input, will be shown when voice is selected
125
- )
126
  ],
127
  outputs=[
128
  "text", # Display the result text
 
80
  return f"Error: Unable to process the query. Please check the syntax. Error: {e}", None
81
 
82
  # Gradio interface function to handle the input
83
+ def calculator(text_input=None, audio=None):
84
+ # Check if an audio file is provided, then process it
85
+ if audio:
86
  query = voice_to_text_from_microphone(audio)
87
  if query.lower() == "sorry, i could not understand the audio.":
88
  return query, None
89
 
90
+ print(f"Original Query (Audio): {query}")
91
 
92
  # Convert speech to math expression
93
  query = convert_speech_to_math(query)
94
  print(f"Converted Math Expression: {query}")
95
+
96
+ elif text_input:
97
  # If text input is provided directly
98
  query = text_input
99
  print(f"Original Query (Text): {query}")
 
108
  interface = gr.Interface(
109
  fn=calculator,
110
  inputs=[
 
 
 
 
 
111
  gr.Textbox(
112
+ label="Enter a Math Expression (Text Input)",
113
+ placeholder="Type your math expression here..."
114
+ ), # Option for text input
 
115
  gr.Audio(
116
+ label="Upload an Audio File with a Math Expression",
117
+ type="filepath"
118
+ ), # Option for uploading audio file
 
119
  ],
120
  outputs=[
121
  "text", # Display the result text