Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import sympy as sp
|
2 |
import gradio as gr
|
3 |
import re
|
4 |
-
from gtts import gTTS
|
5 |
import os
|
|
|
|
|
6 |
|
7 |
# Function to intelligently detect and fix input errors using simple AI-based rules
|
8 |
def intelligent_error_correction(query):
|
@@ -51,13 +52,14 @@ def process_math(query):
|
|
51 |
result_text = f"The result is: {result}"
|
52 |
tts = gTTS(result_text, lang="en")
|
53 |
tts.save("response.mp3")
|
54 |
-
os.system("start response.mp3" if os.name == "nt" else "afplay response.mp3") # Play the speech output
|
55 |
|
56 |
-
|
|
|
|
|
57 |
except Exception as e:
|
58 |
# If there is an error, suggest corrections
|
59 |
suggestions = "\n".join(intelligent_error_correction(query))
|
60 |
-
return f"Error: Unable to process the query. Details: {e}. Suggestions to fix:\n{suggestions}"
|
61 |
|
62 |
# Function to handle voice input (speech-to-text)
|
63 |
def voice_to_text(audio):
|
@@ -91,7 +93,7 @@ def start_interface():
|
|
91 |
gr.Audio(type="filepath", label="Speak a Math Expression (e.g., factorial(5), permutation(5, 3), log(10))"), # Voice input (required)
|
92 |
gr.Textbox(label="Or Type a Math Expression (Optional)", placeholder="Type your math expression here...") # Optional text input
|
93 |
],
|
94 |
-
outputs="text",
|
95 |
title="Advanced Math Solver",
|
96 |
description="Solve advanced math problems including permutations, combinations, factorials, powers, and logarithms. Use speech or text input for accessibility.",
|
97 |
live=True
|
@@ -101,3 +103,4 @@ def start_interface():
|
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
start_interface()
|
|
|
|
1 |
import sympy as sp
|
2 |
import gradio as gr
|
3 |
import re
|
|
|
4 |
import os
|
5 |
+
import speech_recognition as sr
|
6 |
+
from gtts import gTTS
|
7 |
|
8 |
# Function to intelligently detect and fix input errors using simple AI-based rules
|
9 |
def intelligent_error_correction(query):
|
|
|
52 |
result_text = f"The result is: {result}"
|
53 |
tts = gTTS(result_text, lang="en")
|
54 |
tts.save("response.mp3")
|
|
|
55 |
|
56 |
+
# Return the result as audio
|
57 |
+
return result_text, "response.mp3"
|
58 |
+
|
59 |
except Exception as e:
|
60 |
# If there is an error, suggest corrections
|
61 |
suggestions = "\n".join(intelligent_error_correction(query))
|
62 |
+
return f"Error: Unable to process the query. Details: {e}. Suggestions to fix:\n{suggestions}", None
|
63 |
|
64 |
# Function to handle voice input (speech-to-text)
|
65 |
def voice_to_text(audio):
|
|
|
93 |
gr.Audio(type="filepath", label="Speak a Math Expression (e.g., factorial(5), permutation(5, 3), log(10))"), # Voice input (required)
|
94 |
gr.Textbox(label="Or Type a Math Expression (Optional)", placeholder="Type your math expression here...") # Optional text input
|
95 |
],
|
96 |
+
outputs=["text", "audio"],
|
97 |
title="Advanced Math Solver",
|
98 |
description="Solve advanced math problems including permutations, combinations, factorials, powers, and logarithms. Use speech or text input for accessibility.",
|
99 |
live=True
|
|
|
103 |
|
104 |
if __name__ == "__main__":
|
105 |
start_interface()
|
106 |
+
|