Spaces:
Paused
Paused
# This is a Gradio app that simulates the functionality of the provided Tkinter application. | |
# It includes a text input, a voice input button, and a response area to display the AI's response. | |
import gradio as gr | |
import asyncio | |
from ai_system.ai_core import AICore | |
import speech_recognition as sr | |
# Initialize the AI core | |
ai = AICore() | |
# Function to process the query and get the AI response | |
async def process_query(query): | |
result = await ai.generate_response(query, 1) | |
return result['response'] | |
# Function to handle the text input submission | |
def submit_query(query): | |
if not query: | |
return "" | |
response = asyncio.run(process_query(query)) | |
return f"Response: {response}" | |
# Function to handle voice input | |
def listen_voice_command(): | |
recognizer = sr.Recognizer() | |
with sr.Microphone() as source: | |
print("Listening for voice command...") | |
audio = recognizer.listen(source) | |
try: | |
command = recognizer.recognize_google(audio) | |
return command | |
except sr.UnknownValueError: | |
return "Voice command not recognized." | |
except sr.RequestError: | |
return "Could not request results; check your network connection." | |
# Create the Gradio interface | |
with gr.Blocks() as demo: | |
query_entry = gr.Textbox(label="Enter your query") | |
response_area = gr.Textbox(label="Response") | |
submit_button = gr.Button("Submit") | |
voice_button = gr.Button("Voice Input") | |
# Set up the event listeners | |
submit_button.click(submit_query, inputs=query_entry, outputs=response_area) | |
voice_button.click(listen_voice_command, outputs=query_entry) | |
# Launch the Gradio app | |
demo.launch(show_error=True) |