|
import tkinter as tk |
|
from tkinter import messagebox |
|
import asyncio |
|
from ai_system.ai_core import AICore |
|
import speech_recognition as sr |
|
import pyttsx3 |
|
|
|
class AIApplication(tk.Tk): |
|
def __init__(self): |
|
super().__init__() |
|
self.ai = AICore() |
|
self.speech_recognizer = sr.Recognizer() |
|
self.title("AI Assistant - Final Version") |
|
self.geometry("1200x700") |
|
self._init_ui() |
|
|
|
def _init_ui(self): |
|
self.query_entry = tk.Entry(self, width=100) |
|
self.query_entry.pack(pady=10) |
|
tk.Button(self, text="Submit", command=self._submit_query).pack() |
|
self.response_area = tk.Text(self, width=120, height=30) |
|
self.response_area.pack(pady=10) |
|
tk.Button(self, text="Voice Input", command=self._listen_voice_command).pack() |
|
|
|
def _submit_query(self): |
|
query = self.query_entry.get() |
|
if not query: |
|
return |
|
async def process(): |
|
result = await self.ai.generate_response(query, 1) |
|
self.response_area.insert(tk.END, f"Response: {result['response']} |
|
|
|
") |
|
asyncio.run_coroutine_threadsafe(process(), asyncio.get_event_loop()) |
|
|
|
def _listen_voice_command(self): |
|
with sr.Microphone() as source: |
|
print("Listening for voice command...") |
|
audio = self.speech_recognizer.listen(source) |
|
try: |
|
command = self.speech_recognizer.recognize_google(audio) |
|
self.query_entry.delete(0, tk.END) |
|
self.query_entry.insert(0, command) |
|
self._submit_query() |
|
except: |
|
print("Voice command not recognized.") |
|
|
|
if __name__ == "__main__": |
|
app = AIApplication() |
|
app.mainloop() |
|
|