from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.clock import Clock
import threading
import speech_recognition as sr
from google import genai
API_KEY = "AIzaSyD0JOirJgfrNNViibl0YlIhZCDVWWOcNEw"
client = genai.Client(api_key=API_KEY)
class JarvisApp(App):
def build(self):
self.is_active = False
self.layout = BoxLayout(orientation='vertical', padding=20)
self.status_label = Label(text="🤖 JARVIS: Standing By...\n(Say 'Jarvis' to Activate)", font_size='22sp', halign='center')
self.layout.add(self.status_label)
threading.Thread(target=self.start_jarvis_listening, daemon=True).start()
return self.layout
def update_ui_text(self, text, *args):
self.status_label.text = text
def ask_gemini(self, question):
try:
response = client.models.generate_content(model='gemini-1.5-flash', contents=question)
return response.text
except:
return "Connection error, sir."
def start_jarvis_listening(self):
r = sr.Recognizer()
r.dynamic_energy_threshold = True
while True:
with sr.Microphone() as source:
try:
audio = r.listen(source, timeout=None, phrase_time_limit=5)
voice_input = r.recognize_google(audio).lower().strip()
if voice_input:
if "jarvis" in voice_input and not self.is_active:
if "sleep" not in voice_input:
self.is_active = True
Clock.schedule_once(lambda dt: self.update_ui_text("🤖 JARVIS: Active & Listening..."))
continue
if "jarvis sleep" in voice_input:
if self.is_active:
self.is_active = False
Clock.schedule_once(lambda dt: self.update_ui_text("🤖 JARVIS: Sleeping...\n(Say 'Jarvis' to Wake)"))
continue
if self.is_active:
query = voice_input.replace("jarvis", "").strip()
if query:
Clock.schedule_once(lambda dt: self.update_ui_text(f"🧠 Thinking..."))
answer = self.ask_gemini(query)
Clock.schedule_once(lambda dt: self.update_ui_text(f"🤖 JARVIS:\n{answer}"))
except:
continue
if name == 'main':
JarvisApp().run()
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.clock import Clock
import threading
import speech_recognition as sr
from google import genai
API_KEY = "AIzaSyD0JOirJgfrNNViibl0YlIhZCDVWWOcNEw"
client = genai.Client(api_key=API_KEY)
class JarvisApp(App):
def build(self):
self.is_active = False
self.layout = BoxLayout(orientation='vertical', padding=20)
self.status_label = Label(text="🤖 JARVIS: Standing By...\n(Say 'Jarvis' to Activate)", font_size='22sp', halign='center')
self.layout.add(self.status_label)
threading.Thread(target=self.start_jarvis_listening, daemon=True).start()
return self.layout
if name == 'main':
JarvisApp().run()