-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewtest.py
132 lines (110 loc) · 3.07 KB
/
newtest.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
$ pip install google-generativeai
"""
import os
import time
from pydub.playback import play
from pydub import AudioSegment
import pyttsx3
import google.generativeai as genai
genai.configure(api_key="myapi")
engine = pyttsx3.init()
engine.setProperty("rate", 145)
with open("instructions.txt","r") as F1,open("teachers.txt","r") as F2:
instructions = F1.read()
teachers = F2.read()
# Create the model
generation_config = {
"temperature": 2,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 100,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
# safety_settings = Adjust safety settings
# See https://ai.google.dev/gemini-api/docs/safety-settings
system_instruction=instructions
)
history=[
{
"role": "user",
"parts": [
teachers,
],
}
]
chat_session = model.start_chat(
history=history
)
# message = "Welcome! I'm Rishi, the virtual assistant for Maria Assumpta Convent School. How can I help you today?"
# print(message)
# engine.say(message)
# engine.runAndWait()
def playthis(file):
sound = AudioSegment.from_file(file)
play(sound)
def capture():
os.system("libcamera-jpeg --rotation 180 -o ~/Desktop/new/image_file/test.jpg -n")
while True:
text=input("Enter what you want to ask Rishi: ")
if 'listen rishi' in text:
ac = "(Rishi Activation Sound)"
print(f"\r{ac}",end="") # print("\r(Rishi Activation Sound)",end='')
playthis('activation_sound.mp3')
wb = "welcome back "
print(f"\r{wb}")
engine.say(wb)
engine.runAndWait()
flag = True
continue
if 'capture' in text:
print("Processing...")
capture()
myfile = genai.upload_file("image_file/test.jpg")
print("Processing")
result = model.generate_content([myfile, "\n\n", "Can you tell me about this photo?"])
a = result.text
a = a.replace("*","")
print(a)
engine.say(a)
engine.runAndWait()
continue
if 'details' and 'photo' in text:
myfile = genai.upload_file("image_file/test.jpg")
print("Processing")
d = input("Enter what you want to ask about the photo: ")
result = model.generate_content([myfile, "\n\n", d])
a = result.text
a = a.replace("*","")
print(a)
engine.say(a)
engine.runAndWait()
continue
if 'please wait' in text:
print("Of course! Take your time, and let me know when you're ready.")
engine.say("Of course! Take your time, and let me know when you're ready.")
engine.runAndWait()
flag = False
continue
if 'stop' in text:
response = chat_session.send_message(text)
a=response.text
a = a.replace("*","")
print("Rishi: ",a)
engine.say("Goodbye, shutting down the system.")
engine.runAndWait()
time.sleep(1.5)
playthis('deactivation.mp3')
break
else:
response = chat_session.send_message(text)
a=response.text
a = a.replace("*","")
print("You:",text)
print("Rishi:",a)
# engine.setProperty('rate',400)
engine.say(a)
engine.runAndWait()