Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,15 +22,10 @@ def process_math(query):
|
|
22 |
tts = gTTS(result_text, lang="en")
|
23 |
tts.save("response.mp3")
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
os.system("start response.mp3")
|
28 |
-
else: # macOS/Linux
|
29 |
-
os.system("afplay response.mp3") # For macOS/Linux, you may need to use 'mpg123' or other audio players
|
30 |
-
|
31 |
-
return result_text
|
32 |
except Exception as e:
|
33 |
-
return f"Error: Unable to process the query. Please check the syntax. Error: {e}"
|
34 |
|
35 |
# Function to handle voice input (speech-to-text)
|
36 |
def voice_to_text(audio):
|
@@ -99,7 +94,7 @@ def calculator(audio=None, text_input=None):
|
|
99 |
query = text_input
|
100 |
print(f"Text Input: {query}") # Debugging: Print detected text input
|
101 |
else:
|
102 |
-
return "No valid input provided."
|
103 |
|
104 |
# Process the math problem
|
105 |
return process_math(query)
|
@@ -113,7 +108,10 @@ def start_interface():
|
|
113 |
gr.Audio(type="filepath", label="Speak a Math Expression (e.g., factorial(5), differentiate x squared, integrate sin(x), matrix([[1, 2], [3, 4]]) )"), # Voice input (required)
|
114 |
gr.Textbox(label="Or Type a Math Expression (Optional)", placeholder="Type your math expression here...") # Optional text input
|
115 |
],
|
116 |
-
outputs=
|
|
|
|
|
|
|
117 |
title="Advanced Math Solver",
|
118 |
description="Solve advanced math problems including factorials, permutations, combinations, logarithms, differentiation, integration, matrices, trigonometric functions, and more. Use speech or text input for accessibility.",
|
119 |
live=True
|
|
|
22 |
tts = gTTS(result_text, lang="en")
|
23 |
tts.save("response.mp3")
|
24 |
|
25 |
+
# Return the result text for display and audio for listening
|
26 |
+
return result_text, "response.mp3"
|
|
|
|
|
|
|
|
|
|
|
27 |
except Exception as e:
|
28 |
+
return f"Error: Unable to process the query. Please check the syntax. Error: {e}", None
|
29 |
|
30 |
# Function to handle voice input (speech-to-text)
|
31 |
def voice_to_text(audio):
|
|
|
94 |
query = text_input
|
95 |
print(f"Text Input: {query}") # Debugging: Print detected text input
|
96 |
else:
|
97 |
+
return "No valid input provided.", None
|
98 |
|
99 |
# Process the math problem
|
100 |
return process_math(query)
|
|
|
108 |
gr.Audio(type="filepath", label="Speak a Math Expression (e.g., factorial(5), differentiate x squared, integrate sin(x), matrix([[1, 2], [3, 4]]) )"), # Voice input (required)
|
109 |
gr.Textbox(label="Or Type a Math Expression (Optional)", placeholder="Type your math expression here...") # Optional text input
|
110 |
],
|
111 |
+
outputs=[
|
112 |
+
"text", # Show the text result
|
113 |
+
gr.Audio(label="Listen to the result") # Provide the audio result
|
114 |
+
],
|
115 |
title="Advanced Math Solver",
|
116 |
description="Solve advanced math problems including factorials, permutations, combinations, logarithms, differentiation, integration, matrices, trigonometric functions, and more. Use speech or text input for accessibility.",
|
117 |
live=True
|