File size: 1,630 Bytes
493d5e8
 
c07e124
493d5e8
 
 
 
62a8e44
 
 
 
 
 
493d5e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62a8e44
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
# 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