File size: 1,696 Bytes
493d5e8
 
c07e124
493d5e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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)