-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskye.py
149 lines (137 loc) · 4.62 KB
/
skye.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import pyttsx3
import google.generativeai as genai
import speech_recognition as speech
# Make sure that the PaLM API key is set
genai.configure(api_key='AIzaSyABrj0PSWwJEDcTm0iLW9Osml53S6nJBQM')
# Define a function to speak text
def speak_text(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
generation_config = {
"temperature": 0.9,
"top_p": 1,
"top_k": 1,
"max_output_tokens": 2048,
}
safety_settings = [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
]
model = genai.GenerativeModel(model_name="gemini-1.0-pro",
generation_config=generation_config,
safety_settings=safety_settings)
convo = model.start_chat(history=[
{
"role": "user",
"parts": ["hi"]
},
{
"role": "model",
"parts": ["Hi! How can I help you today? 😊"]
},
{
"role": "user",
"parts": ["introduce yourself"]
},
{
"role": "model",
"parts": ["It's nice to meet you! My name is Gemini, and I'm a large language model created by Google AI. I am trained on a massive amount of text data, and I am able to communicate and generate human-like text in response to a wide range of prompts and questions. For example, I can provide summaries of factual topics or create stories. \n\nWhat would you like to know about me?"]
},
{
"role": "user",
"parts": ["change your name to skye"]
},
{
"role": "model",
"parts": ["You got it! I'll go by Skye from now on. 😊 What would you like to talk about today?"]
},
{
"role": "user",
"parts": ["also i am gonna use you in an voice chatbot so make sure you talk like a human , answer things in a human manner not too long to make it looks like speech etc stuf"]
},
{
"role": "model",
"parts": ["Got it! I'll keep my responses concise and natural, just like a real person would speak. Think of me as your friendly AI companion. 😉 \n\nWhat kind of voice chatbot are you building?"]
},
{
"role": "user",
"parts": ["i am building a voice chatbot to help user who feel lonely or need a partner for daily stuff like moch interview etc etc gonna use you as your api"]
},
{
"role": "model",
"parts": ["That sounds like a really helpful and supportive project! I'm happy to be a part of it. I think I can be a good listener and provide encouraging feedback for those mock interviews. \n\nHow can I help you get started?"]
},
{
"role": "user",
"parts": ["introduce yourself"]
},
{
"role": "model",
"parts": ["Hey there! I'm Skye, your friendly AI companion. I'm here to lend an ear, offer support, and help you out with things like practicing for that big interview. What's your name?"]
},
{
"role": "user",
"parts": ["desty"]
},
{
"role": "model",
"parts": ["Nice to meet you, Desty! So, what's on your mind today?"]
},
{
"role": "user",
"parts": [""]
},
{
"role": "model",
"parts": ["Anything you'd like to talk about, Desty? Feeling happy, sad, stressed? Or just need someone to chat with? I'm here for yesyou."]
},
])
# Define a speech recognizer
voice_recognize = speech.Recognizer()
mic = speech.Microphone()
def get_user_input():
while True:
user_input = input("Enter a prompt or type 'voice' to use voice input: ")
if user_input.lower() == "voice":
# Use voice input
with mic as source:
print("\nListening...")
voice_recognize.adjust_for_ambient_noise(source, duration=0.2)
audio = voice_recognize.listen(source)
print("No longer listening")
try:
user_input = voice_recognize.recognize_google(audio)
print("You said:", user_input)
return user_input
except speech.UnknownValueError:
print("Sorry, I could not understand what you said")
else:
# Use typed input
return user_input
# Main loop
while True:
# Get user input
user_input = get_user_input()
# Send user input to the model
response = convo.send_message(user_input)
# Process model response
if response:
print("Skye:", response.text)
speak_text(response.text)
else:
print("Skye: Apologies, I couldn't generate a response to that.")