-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
136 lines (111 loc) · 3.54 KB
/
main.py
File metadata and controls
136 lines (111 loc) · 3.54 KB
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
from llamaapi import LlamaAPI
from dotenv import load_dotenv
load_dotenv()
import os
import json
import pyfirmata
llama = LlamaAPI(os.getenv("API_KEY"))
from speech import record_audio, transcribe
from speechSynthesis import gen
import speech_recognition as sr
import requests
r = sr.Recognizer()
def listen():
try:
with sr.Microphone() as source:
print("Listening")
aud = r.listen(source)
print("Processing")
txt = r.recognize_google(aud)
txt = txt.lower()
return txt
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
return "Errorred"
except sr.UnknownValueError:
print("unknown error occurred")
return "Errorred"
"""
from transformers import AutoModelForCausalLM, AutoTokenizer
from PIL import Image
model_id = "vikhyatk/moondream2"
revision = "2024-05-20"
model = AutoModelForCausalLM.from_pretrained(
model_id, trust_remote_code=True, revision=revision
)
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
image = Image.open('sample.jpg')
enc_image = model.encode_image(image)
description = model.answer_question(enc_image, "Describe this image.", tokenizer)
"""
description = "Black"
def rightArm(deg):
print(f"rightArm() Function Working, Parameter Recieved is {deg}")
def leftArm(deg):
print(f"leftArm() Function Working, Parameter Recieved is {deg}")
happy = "happy"
sad = "sad"
angry = "angry"
neutral = "neutral"
surprised = "surprised"
disgusted = "disgusted"
scared = "scared"
laughing = "laughing"
crying = "crying"
data = {
"model": "phi3:mini",
"messages": [
{
"role": "user",
"content": "ALWAYS RESPOND BRIEFLY AND IN 1 SENTENCE, NEVER USE MORE THAN 1 SENTENCE. ALL NUMBERS YOU HAVE TO SPELL OUT. DO NOT RESPOND ANYTHING ELSE. ONLY THAT 1 SENTENCE"
}
],
"stream": False
}
data2 = {
"model": "phi3:mini",
"messages": [
{
"role": "user",
"content": "tell it to do functions here"
}
],
"stream": False
}
def ask(q):
url = "http://localhost:11434/api/chat"
data["messages"].append({"role": "user", "content": q})
response = requests.post(url, json=data)
response = response.json()
return response["message"]["content"]
def functions(q):
url = "http://localhost:11434/api/chat"
data["messages"].append({"role": "user", "content": q})
response = requests.post(url, json=data)
response = response.json()
return response["message"]["content"]
def facialExpression(emotion):
print(f"Facial Expression Function Working, Parameter Recieved is {emotion}")
while True:
prompt = transcribe(record_audio())
print("Audio Processed \n\n")
print(f"You: {prompt}")
output = ask(prompt)
#func = functions(prompt)
print(f"Bot: {output}")
gen(output)
#playAudio()
#api_request_json["messages"].append({"role": "user", "content": prompt})
#response = llama.run(api_request_json)
#responseArray = json.dumps(response.json()["choices"][0]["message"]["content"]).replace('"', '').split("$")
#print(responseArray[0])
#api_request_json["messages"].append({"role": "system", "content": responseArray[0]})
#array = responseArray[1].replace(" ", "").split(',')
# Make the LLM Send it separated by commas then split that thing at commas and push to array
"""
for i in array:
try:
eval(i)
except:
print("Error in function")
"""