Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
84 |
-
if
|
85 |
-
|
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 (
|
91 |
|
92 |
# Convert speech to math expression
|
93 |
query = convert_speech_to_math(query)
|
94 |
print(f"Converted Math Expression: {query}")
|
95 |
-
|
96 |
-
elif
|
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="
|
118 |
-
placeholder="Type your math expression here..."
|
119 |
-
|
120 |
-
),
|
121 |
gr.Audio(
|
122 |
-
label="Upload an Audio File
|
123 |
-
type="filepath"
|
124 |
-
|
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
|