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 | |
| import speech_recognition as sr | |
| # Mock AI core for demonstration purposes | |
| class AICore: | |
| async def generate_response(self, query, user_id): | |
| await asyncio.sleep(1) # Simulate async processing | |
| return {"response": f"AI Response to: {query}"} | |
| # 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 |