Spaces:
Paused
Paused
Create APP.py
Browse files
APP.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tkinter as tk
|
| 2 |
+
from tkinter import messagebox
|
| 3 |
+
import asyncio
|
| 4 |
+
from ai_system.ai_core import AICore
|
| 5 |
+
import speech_recognition as sr
|
| 6 |
+
import pyttsx3
|
| 7 |
+
|
| 8 |
+
class AIApplication(tk.Tk):
|
| 9 |
+
def __init__(self):
|
| 10 |
+
super().__init__()
|
| 11 |
+
self.ai = AICore()
|
| 12 |
+
self.speech_recognizer = sr.Recognizer()
|
| 13 |
+
self.title("Falcondette")
|
| 14 |
+
self.geometry("1200x700")
|
| 15 |
+
self._init_ui()
|
| 16 |
+
|
| 17 |
+
def _init_ui(self):
|
| 18 |
+
self.query_entry = tk.Entry(self, width=100)
|
| 19 |
+
self.query_entry.pack(pady=10)
|
| 20 |
+
tk.Button(self, text="Submit", command=self._submit_query).pack()
|
| 21 |
+
self.response_area = tk.Text(self, width=120, height=30)
|
| 22 |
+
self.response_area.pack(pady=10)
|
| 23 |
+
tk.Button(self, text="Voice Input", command=self._listen_voice_command).pack()
|
| 24 |
+
|
| 25 |
+
def _submit_query(self):
|
| 26 |
+
query = self.query_entry.get()
|
| 27 |
+
if not query:
|
| 28 |
+
return
|
| 29 |
+
async def process():
|
| 30 |
+
result = await self.ai.generate_response(query, 1)
|
| 31 |
+
self.response_area.insert(tk.END, f"Response: {result['response']}
|
| 32 |
+
")
|
| 33 |
+
asyncio.run_coroutine_threadsafe(process(), asyncio.get_event_loop())
|
| 34 |
+
|
| 35 |
+
def _listen_voice_command(self):
|
| 36 |
+
with sr.Microphone() as source:
|
| 37 |
+
print("Listening for voice command...")
|
| 38 |
+
audio = self.speech_recognizer.listen(source)
|
| 39 |
+
try:
|
| 40 |
+
command = self.speech_recognizer.recognize_google(audio)
|
| 41 |
+
self.query_entry.delete(0, tk.END)
|
| 42 |
+
self.query_entry.insert(0, command)
|
| 43 |
+
self._submit_query()
|
| 44 |
+
except:
|
| 45 |
+
print("Voice command not recognized.")
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
app = AIApplication()
|
| 49 |
+
app.mainloop()
|