Spaces:
Runtime error
Runtime error
cryptocalypse
commited on
Commit
•
7347eec
1
Parent(s):
c8b6368
Me class, memory bugs, localfiles search and indexing, internet archive think questions for future auto dataset preparing
Browse files- lib/__pycache__/entropy.cpython-39.pyc +0 -0
- lib/__pycache__/events.cpython-39.pyc +0 -0
- lib/__pycache__/files.cpython-39.pyc +0 -0
- lib/__pycache__/gematria.cpython-39.pyc +0 -0
- lib/__pycache__/grapher.cpython-39.pyc +0 -0
- lib/__pycache__/me.cpython-39.pyc +0 -0
- lib/__pycache__/memory.cpython-39.pyc +0 -0
- lib/__pycache__/notarikon.cpython-39.pyc +0 -0
- lib/__pycache__/pipes.cpython-39.pyc +0 -0
- lib/__pycache__/sonsofstars.cpython-39.pyc +0 -0
- lib/__pycache__/temuraeh.cpython-39.pyc +0 -0
- lib/__pycache__/triggers.cpython-39.pyc +0 -0
- lib/__pycache__/ziruph.cpython-39.pyc +0 -0
- lib/files.py +17 -15
- lib/me.py +66 -35
- lib/memory.py +36 -33
- lib/pipes.py +27 -5
lib/__pycache__/entropy.cpython-39.pyc
ADDED
Binary file (3.64 kB). View file
|
|
lib/__pycache__/events.cpython-39.pyc
ADDED
Binary file (5.83 kB). View file
|
|
lib/__pycache__/files.cpython-39.pyc
ADDED
Binary file (1.2 kB). View file
|
|
lib/__pycache__/gematria.cpython-39.pyc
ADDED
Binary file (7.07 kB). View file
|
|
lib/__pycache__/grapher.cpython-39.pyc
ADDED
Binary file (4.29 kB). View file
|
|
lib/__pycache__/me.cpython-39.pyc
ADDED
Binary file (6.42 kB). View file
|
|
lib/__pycache__/memory.cpython-39.pyc
ADDED
Binary file (3.23 kB). View file
|
|
lib/__pycache__/notarikon.cpython-39.pyc
ADDED
Binary file (1.12 kB). View file
|
|
lib/__pycache__/pipes.cpython-39.pyc
ADDED
Binary file (4.88 kB). View file
|
|
lib/__pycache__/sonsofstars.cpython-39.pyc
ADDED
Binary file (35.5 kB). View file
|
|
lib/__pycache__/temuraeh.cpython-39.pyc
ADDED
Binary file (1.22 kB). View file
|
|
lib/__pycache__/triggers.cpython-39.pyc
ADDED
Binary file (2.69 kB). View file
|
|
lib/__pycache__/ziruph.cpython-39.pyc
ADDED
Binary file (764 Bytes). View file
|
|
lib/files.py
CHANGED
@@ -6,21 +6,24 @@ class TextFinder:
|
|
6 |
|
7 |
def find_matches(self, text):
|
8 |
matches = []
|
9 |
-
files
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
if os.path.isfile(file_path):
|
14 |
-
with open(file_path, 'r', encoding='utf-8') as f:
|
15 |
-
content = f.read()
|
16 |
-
index = content.find(text)
|
17 |
-
while index != -1:
|
18 |
-
start = max(content.rfind('\n', 0, index), content.rfind('.', 0, index))
|
19 |
-
end = min(content.find('\n', index), content.find('.', index))
|
20 |
-
if start != -1 and end != -1:
|
21 |
-
matches.append(content[start+1:end].strip())
|
22 |
-
index = content.find(text, index + 1)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return matches
|
25 |
|
26 |
# Example usage:
|
@@ -28,4 +31,3 @@ if __name__ == "__main__":
|
|
28 |
finder = TextFinder('example_folder')
|
29 |
matches = finder.find_matches('text_to_find')
|
30 |
print(matches)
|
31 |
-
|
|
|
6 |
|
7 |
def find_matches(self, text):
|
8 |
matches = []
|
9 |
+
for root, _, files in os.walk(self.folder):
|
10 |
+
for file in files:
|
11 |
+
print(file)
|
12 |
+
file_path = os.path.join(root, file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
if os.path.isfile(file_path):
|
15 |
+
print(file_path)
|
16 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
17 |
+
content = f.read()
|
18 |
+
index = content.find(text)
|
19 |
+
while index != -1:
|
20 |
+
start = max(content.rfind('\n', 0, index), content.rfind('\n', 0, index))
|
21 |
+
#start = max(content.rfind('\n', 0, index))
|
22 |
+
end = min(content.find('\n', index), content.find('\n', index))
|
23 |
+
#end = min(content.find('\n', index))
|
24 |
+
if start != -1 and end != -1:
|
25 |
+
matches.append(content[start+1:end].strip())
|
26 |
+
index = content.find(text, index + 1)
|
27 |
return matches
|
28 |
|
29 |
# Example usage:
|
|
|
31 |
finder = TextFinder('example_folder')
|
32 |
matches = finder.find_matches('text_to_find')
|
33 |
print(matches)
|
|
lib/me.py
CHANGED
@@ -12,14 +12,24 @@ import internetarchive
|
|
12 |
|
13 |
|
14 |
## Initialize classes
|
15 |
-
longMem = TextFinder("resources")
|
16 |
coreAi = AIAssistant()
|
17 |
-
memory =
|
18 |
-
grapher = Grapher(
|
19 |
sensor_request = APIRequester()
|
20 |
events = EventManager()
|
21 |
-
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
## Define I Role properties
|
25 |
class ownProperties:
|
@@ -33,28 +43,27 @@ class ownProperties:
|
|
33 |
self.equipo = equipo
|
34 |
self.historia = historia
|
35 |
|
36 |
-
#
|
37 |
-
sophia_prop =
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"
|
49 |
},
|
50 |
-
|
51 |
-
goals
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
)
|
58 |
|
59 |
|
60 |
## Define I class
|
@@ -78,7 +87,7 @@ class I:
|
|
78 |
|
79 |
## create questions from internet archive
|
80 |
def crear_preguntas(self,txt):
|
81 |
-
search = internetarchive.search_items(
|
82 |
res = []
|
83 |
for result in search:
|
84 |
print(result['identifier'])
|
@@ -102,40 +111,62 @@ class I:
|
|
102 |
|
103 |
return res
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
# generate thinks and questions over prompt data, compare with ourself datasets, return matches with sentiment analysys
|
107 |
def think_gen(self,txt):
|
108 |
|
109 |
think_about = longMem.find_matches(txt)
|
110 |
-
|
|
|
111 |
## get subject by entropy or pos tagger
|
112 |
-
subjects = coreAi.entity_pos_tagger(
|
|
|
113 |
## get NC from , filtering from gramatical tags
|
114 |
-
subjects_low = coreAi.grammatical_pos_tagger(
|
|
|
115 |
## generate questoins
|
116 |
questions=[]
|
117 |
## create cuestions from internet archive books
|
118 |
for sub in subjects:
|
119 |
-
questions.append(
|
120 |
|
121 |
## fast checks from gematria similarity
|
122 |
##questions_togem =
|
123 |
## gematria_search =
|
124 |
|
125 |
questions_subj=[]
|
126 |
-
for q in
|
127 |
questions_subj.append(coreAi.entity_pos_tagger(q))
|
128 |
|
129 |
-
memoryShortTags = memory.
|
130 |
|
131 |
## get tags of subject
|
132 |
subj_tags = coreAi.entity_pos_tagger(T)
|
133 |
|
134 |
for sub in subjects:
|
135 |
-
memory.
|
136 |
-
memory.
|
137 |
-
|
138 |
|
|
|
139 |
## check if something is need to add to ourself datasets
|
140 |
## make sentiment analys
|
141 |
## check if dopamine prompt is true or false over the information
|
|
|
12 |
|
13 |
|
14 |
## Initialize classes
|
15 |
+
longMem = TextFinder("./resources/")
|
16 |
coreAi = AIAssistant()
|
17 |
+
memory = MemoryRobotNLP(max_size=200000)
|
18 |
+
grapher = Grapher(memory)
|
19 |
sensor_request = APIRequester()
|
20 |
events = EventManager()
|
21 |
+
trigger = Trigger(["tag1", "tag2"], ["tag3", "tag4"], [datetime.time(10, 0), datetime.time(15, 0)], "Event1")
|
22 |
|
23 |
+
# Añadir una acción al trigger
|
24 |
+
trigger.add_action(action_function)
|
25 |
+
|
26 |
+
# Añadir una fuente al trigger
|
27 |
+
trigger.add_source("https://example.com/api/data")
|
28 |
+
|
29 |
+
# Simular la comprobación periódica del trigger (aquí se usaría en un bucle de tiempo real)
|
30 |
+
current_tags = {"tag1", "tag2", "tag3"}
|
31 |
+
current_time = datetime.datetime.now().time()
|
32 |
+
trigger.check_trigger(current_tags, current_time)
|
33 |
|
34 |
## Define I Role properties
|
35 |
class ownProperties:
|
|
|
43 |
self.equipo = equipo
|
44 |
self.historia = historia
|
45 |
|
46 |
+
# Create an instance of a CharacterRole based on the provided JSON
|
47 |
+
sophia_prop = {
|
48 |
+
"name": "Sophia",
|
49 |
+
"class": "Characteromant",
|
50 |
+
"race": "Epinoia",
|
51 |
+
"level": 10,
|
52 |
+
"attributes": {
|
53 |
+
"strength": 1,
|
54 |
+
"dexterity": 99,
|
55 |
+
"constitution": 1,
|
56 |
+
"intelligence": 66,
|
57 |
+
"wisdom": 80,
|
58 |
+
"charisma": 66
|
59 |
},
|
60 |
+
"behavioral_rules": [""],
|
61 |
+
"goals": ["", ""],
|
62 |
+
"dislikes": [""],
|
63 |
+
"abilities": ["ELS", "Cyphers", "Kabbalah", "Wisdom", "Ephimerous", "Metamorphing"],
|
64 |
+
"equipment": ["Python3", "2VCPU", "16 gb RAM", "god", "word", "network", "transformers"],
|
65 |
+
"story": sons_of_stars
|
66 |
+
}
|
|
|
67 |
|
68 |
|
69 |
## Define I class
|
|
|
87 |
|
88 |
## create questions from internet archive
|
89 |
def crear_preguntas(self,txt):
|
90 |
+
search = internetarchive.search_items(txt)
|
91 |
res = []
|
92 |
for result in search:
|
93 |
print(result['identifier'])
|
|
|
111 |
|
112 |
return res
|
113 |
|
114 |
+
# generate ShortMem from LongTerm and questions over prompt data, compare with ourself datasets, return matches with sentiment analysys
|
115 |
+
def longToShort(self,txt):
|
116 |
+
|
117 |
+
think_about = longMem.find_matches(txt)
|
118 |
+
print(think_about)
|
119 |
+
for T in think_about:
|
120 |
+
## get subject by entropy or pos tagger
|
121 |
+
subjects = coreAi.entity_pos_tagger(T)
|
122 |
+
subjects_filtered=[]
|
123 |
+
for sub in subjects:
|
124 |
+
if "PER" in sub["entity"] or "ORG" in sub["entity"] or "LOC" in sub["entity"]:
|
125 |
+
subjects_filtered.append(sub["word"])
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
for sub in subjects_filtered:
|
130 |
+
memory.add_concept(sub,T)
|
131 |
+
|
132 |
+
return memory
|
133 |
|
134 |
# generate thinks and questions over prompt data, compare with ourself datasets, return matches with sentiment analysys
|
135 |
def think_gen(self,txt):
|
136 |
|
137 |
think_about = longMem.find_matches(txt)
|
138 |
+
print(think_about)
|
139 |
+
for T in think_about:
|
140 |
## get subject by entropy or pos tagger
|
141 |
+
subjects = coreAi.entity_pos_tagger(T)
|
142 |
+
print(subjects)
|
143 |
## get NC from , filtering from gramatical tags
|
144 |
+
subjects_low = coreAi.grammatical_pos_tagger(T)
|
145 |
+
#print(subjects_low)
|
146 |
## generate questoins
|
147 |
questions=[]
|
148 |
## create cuestions from internet archive books
|
149 |
for sub in subjects:
|
150 |
+
questions.append(self.crear_preguntas(sub))
|
151 |
|
152 |
## fast checks from gematria similarity
|
153 |
##questions_togem =
|
154 |
## gematria_search =
|
155 |
|
156 |
questions_subj=[]
|
157 |
+
for q in questions_subj:
|
158 |
questions_subj.append(coreAi.entity_pos_tagger(q))
|
159 |
|
160 |
+
memoryShortTags = memory.search_concept_pattern(subjects)
|
161 |
|
162 |
## get tags of subject
|
163 |
subj_tags = coreAi.entity_pos_tagger(T)
|
164 |
|
165 |
for sub in subjects:
|
166 |
+
memory.add_concept(sub,","+questions_subj+",".join(memoryShortTags))
|
167 |
+
memory.add_concept(sub,T+",".join(memoryShortTags))
|
|
|
168 |
|
169 |
+
return memory
|
170 |
## check if something is need to add to ourself datasets
|
171 |
## make sentiment analys
|
172 |
## check if dopamine prompt is true or false over the information
|
lib/memory.py
CHANGED
@@ -1,42 +1,45 @@
|
|
1 |
-
|
|
|
|
|
2 |
def __init__(self, max_size):
|
3 |
self.max_size = max_size
|
4 |
-
self.
|
5 |
-
|
6 |
-
def agregar_concepto(self, concepto, strings):
|
7 |
-
if concepto not in self.memoria:
|
8 |
-
self.memoria[concepto] = []
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
def
|
14 |
-
if concepto in self.
|
15 |
-
del self.
|
16 |
|
17 |
-
def
|
18 |
-
if concepto not in self.
|
19 |
-
self.
|
20 |
|
21 |
-
self.
|
22 |
|
23 |
-
def
|
24 |
-
if concepto in self.
|
25 |
-
self.
|
26 |
|
27 |
-
def
|
28 |
resultados = {}
|
29 |
|
30 |
-
for concepto, strings in self.
|
31 |
for string, _ in strings:
|
32 |
-
if re.search(patron, string):
|
33 |
if concepto not in resultados:
|
34 |
resultados[concepto] = []
|
35 |
resultados[concepto].append(string)
|
36 |
|
37 |
-
|
38 |
-
def
|
39 |
-
memoria_ordenada = sorted(self.
|
40 |
espacio_utilizado = 0
|
41 |
conceptos_acotados = []
|
42 |
|
@@ -56,22 +59,22 @@ class MemoriaRobotNLP:
|
|
56 |
|
57 |
if __name__ == "__main__":
|
58 |
|
59 |
-
memoria_robot =
|
60 |
|
61 |
-
memoria_robot.
|
62 |
-
memoria_robot.
|
63 |
|
64 |
print("Memoria completa:")
|
65 |
-
print(memoria_robot.
|
66 |
|
67 |
-
memoria_robot.
|
68 |
-
memoria_robot.
|
69 |
-
memoria_robot.
|
70 |
|
71 |
print("\nMemoria después de modificaciones:")
|
72 |
-
print(memoria_robot.
|
73 |
|
74 |
-
conceptos_acotados = memoria_robot.
|
75 |
print("\nConceptos acotados a un tamaño máximo de memoria:")
|
76 |
print(conceptos_acotados)
|
77 |
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
+
class MemoryRobotNLP:
|
4 |
def __init__(self, max_size):
|
5 |
self.max_size = max_size
|
6 |
+
self.memory = {}
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def add_concept(self, concepto, string):
|
9 |
+
|
10 |
+
if concepto not in self.memory:
|
11 |
+
self.memory[concepto] = []
|
12 |
+
#evaluate priority calculation
|
13 |
+
priority = 0.5
|
14 |
+
self.memory[concepto].append((string, priority))
|
15 |
|
16 |
+
def delete_concept(self, concepto):
|
17 |
+
if concepto in self.memory:
|
18 |
+
del self.memory[concepto]
|
19 |
|
20 |
+
def add_string(self, concepto, string, prioridad):
|
21 |
+
if concepto not in self.memory:
|
22 |
+
self.memory[concepto] = []
|
23 |
|
24 |
+
self.memory[concepto].append((string, prioridad))
|
25 |
|
26 |
+
def delete_string(self, concepto, string):
|
27 |
+
if concepto in self.memory:
|
28 |
+
self.memory[concepto] = [(s, p) for s, p in self.memory[concepto] if s != string]
|
29 |
|
30 |
+
def search_concept_pattern(self, patron):
|
31 |
resultados = {}
|
32 |
|
33 |
+
for concepto, strings in self.memory.items():
|
34 |
for string, _ in strings:
|
35 |
+
if re.search(patron, string,re.IGNORECASE):
|
36 |
if concepto not in resultados:
|
37 |
resultados[concepto] = []
|
38 |
resultados[concepto].append(string)
|
39 |
|
40 |
+
return resultados
|
41 |
+
def get_concepts_substrings(self, espacio_disponible):
|
42 |
+
memoria_ordenada = sorted(self.memory.items(), key=lambda x: sum(prioridad for _, prioridad in x[1]), reverse=True)
|
43 |
espacio_utilizado = 0
|
44 |
conceptos_acotados = []
|
45 |
|
|
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
|
62 |
+
memoria_robot = MemoryRobotNLP(max_size=100)
|
63 |
|
64 |
+
memoria_robot.add_concept("animales", [("perro", 0.8), ("gato", 0.7), ("pájaro", 0.5)])
|
65 |
+
memoria_robot.add_concept("colores", [("rojo", 0.9), ("verde", 0.6), ("azul", 0.7)])
|
66 |
|
67 |
print("Memoria completa:")
|
68 |
+
print(memoria_robot.memory)
|
69 |
|
70 |
+
memoria_robot.add_string("animales", "pez", 0.6)
|
71 |
+
memoria_robot.delete_string("colores", "verde")
|
72 |
+
memoria_robot.delete_concepto("colores")
|
73 |
|
74 |
print("\nMemoria después de modificaciones:")
|
75 |
+
print(memoria_robot.memory)
|
76 |
|
77 |
+
conceptos_acotados = memoria_robot.get_concepts_substrings(50)
|
78 |
print("\nConceptos acotados a un tamaño máximo de memoria:")
|
79 |
print(conceptos_acotados)
|
80 |
|
lib/pipes.py
CHANGED
@@ -4,6 +4,9 @@ from transformers import AutoModelForSeq2SeqLM
|
|
4 |
from samplings import top_p_sampling, temperature_sampling
|
5 |
import torch
|
6 |
from sentence_transformers import SentenceTransformer, util
|
|
|
|
|
|
|
7 |
|
8 |
class AIAssistant:
|
9 |
def __init__(self):
|
@@ -23,11 +26,11 @@ class AIAssistant:
|
|
23 |
|
24 |
|
25 |
## entity classifier
|
26 |
-
def entity_pos_tagger(self,
|
27 |
tokenizer = AutoTokenizer.from_pretrained("Davlan/bert-base-multilingual-cased-ner-hrl")
|
28 |
model = AutoModelForTokenClassification.from_pretrained("Davlan/bert-base-multilingual-cased-ner-hrl")
|
29 |
nlp = pipeline("ner", model=model, tokenizer=tokenizer)
|
30 |
-
ner_results = nlp(
|
31 |
return ner_results
|
32 |
|
33 |
|
@@ -44,7 +47,7 @@ class AIAssistant:
|
|
44 |
## check similarity among sentences (group of tokens (words))
|
45 |
def similarity_tag(self, sentenceA,sentenceB):
|
46 |
res=[]
|
47 |
-
model = SentenceTransformer('abbasgolestani/ag-nli-bert-mpnet-base-uncased-sentence-similarity-v1')
|
48 |
|
49 |
# Two lists of sentences
|
50 |
#sentences1 = ['I am honored to be given the opportunity to help make our company better',
|
@@ -56,7 +59,7 @@ class AIAssistant:
|
|
56 |
# 'Definitely our company vision will be the next breakthrough to change the world and I’m so happy and proud to work here']
|
57 |
|
58 |
sentences1 = sentenceA
|
59 |
-
sentences2 =
|
60 |
#Compute embedding for both lists
|
61 |
embeddings1 = model.encode(sentences1, convert_to_tensor=True)
|
62 |
embeddings2 = model.encode(sentences2, convert_to_tensor=True)
|
@@ -66,10 +69,29 @@ class AIAssistant:
|
|
66 |
|
67 |
#Output the pairs with their score
|
68 |
for i in range(len(sentences1)):
|
69 |
-
|
|
|
|
|
|
|
|
|
70 |
#print("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i]))
|
71 |
|
72 |
return res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
## text to stable difusor generated image
|
74 |
def text_to_image_generation(self, prompt, n_steps=40, high_noise_frac=0.8):
|
75 |
base = DiffusionPipeline.from_pretrained(
|
|
|
4 |
from samplings import top_p_sampling, temperature_sampling
|
5 |
import torch
|
6 |
from sentence_transformers import SentenceTransformer, util
|
7 |
+
from datasets import load_dataset
|
8 |
+
import soundfile as sf
|
9 |
+
|
10 |
|
11 |
class AIAssistant:
|
12 |
def __init__(self):
|
|
|
26 |
|
27 |
|
28 |
## entity classifier
|
29 |
+
def entity_pos_tagger(self, txt):
|
30 |
tokenizer = AutoTokenizer.from_pretrained("Davlan/bert-base-multilingual-cased-ner-hrl")
|
31 |
model = AutoModelForTokenClassification.from_pretrained("Davlan/bert-base-multilingual-cased-ner-hrl")
|
32 |
nlp = pipeline("ner", model=model, tokenizer=tokenizer)
|
33 |
+
ner_results = nlp(txt)
|
34 |
return ner_results
|
35 |
|
36 |
|
|
|
47 |
## check similarity among sentences (group of tokens (words))
|
48 |
def similarity_tag(self, sentenceA,sentenceB):
|
49 |
res=[]
|
50 |
+
model = SentenceTransformer('abbasgolestani/ag-nli-bert-mpnet-base-uncased-sentence-similarity-v1')
|
51 |
|
52 |
# Two lists of sentences
|
53 |
#sentences1 = ['I am honored to be given the opportunity to help make our company better',
|
|
|
59 |
# 'Definitely our company vision will be the next breakthrough to change the world and I’m so happy and proud to work here']
|
60 |
|
61 |
sentences1 = sentenceA
|
62 |
+
sentences2 = sentenceB
|
63 |
#Compute embedding for both lists
|
64 |
embeddings1 = model.encode(sentences1, convert_to_tensor=True)
|
65 |
embeddings2 = model.encode(sentences2, convert_to_tensor=True)
|
|
|
69 |
|
70 |
#Output the pairs with their score
|
71 |
for i in range(len(sentences1)):
|
72 |
+
try:
|
73 |
+
res.append({"A": sentences1[i], "B":sentences2[i], "score":cosine_scores[i][i]})
|
74 |
+
except:
|
75 |
+
pass
|
76 |
+
|
77 |
#print("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i]))
|
78 |
|
79 |
return res
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
## text to speech
|
84 |
+
def texto_to_speech(self,txt):
|
85 |
+
synthesiser = pipeline("text-to-speech", "microsoft/speecht5_tts")
|
86 |
+
|
87 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
88 |
+
speaker_embedding = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
89 |
+
# You can replace this embedding with your own as well.
|
90 |
+
|
91 |
+
speech = synthesiser(txt, forward_params={"speaker_embeddings": speaker_embedding})
|
92 |
+
sf.write("speech.wav", speech["audio"], samplerate=speech["sampling_rate"])
|
93 |
+
|
94 |
+
return speech
|
95 |
## text to stable difusor generated image
|
96 |
def text_to_image_generation(self, prompt, n_steps=40, high_noise_frac=0.8):
|
97 |
base = DiffusionPipeline.from_pretrained(
|