Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from sklearn.neural_network import MLPClassifier
|
|
11 |
from deap import base, creator, tools, algorithms
|
12 |
from transformers import BloomForCausalLM, BloomTokenizerFast
|
13 |
import torch
|
|
|
14 |
|
15 |
# Initialize Example Emotions Dataset
|
16 |
data = {
|
@@ -223,7 +224,7 @@ def handle_idle_state():
|
|
223 |
class SOUL:
|
224 |
def __init__(self, model_name='bigscience/bloom-1b1'):
|
225 |
self.tokenizer = BloomTokenizerFast.from_pretrained(model_name)
|
226 |
-
self.model = BloomForCausalLM.from_pretrained(model_name)
|
227 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
228 |
self.model.to(self.device)
|
229 |
|
@@ -261,12 +262,20 @@ def interact_with_soul(user_input):
|
|
261 |
bloom_response, emotional_response = soul.bridge_ai(user_input)
|
262 |
return bloom_response, emotional_response
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
from deap import base, creator, tools, algorithms
|
12 |
from transformers import BloomForCausalLM, BloomTokenizerFast
|
13 |
import torch
|
14 |
+
import torch.multiprocessing as mp
|
15 |
|
16 |
# Initialize Example Emotions Dataset
|
17 |
data = {
|
|
|
224 |
class SOUL:
|
225 |
def __init__(self, model_name='bigscience/bloom-1b1'):
|
226 |
self.tokenizer = BloomTokenizerFast.from_pretrained(model_name)
|
227 |
+
self.model = BloomForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
|
228 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
229 |
self.model.to(self.device)
|
230 |
|
|
|
262 |
bloom_response, emotional_response = soul.bridge_ai(user_input)
|
263 |
return bloom_response, emotional_response
|
264 |
|
265 |
+
# Function to handle Gradio interface using multiprocessing
|
266 |
+
def launch_gradio():
|
267 |
+
iface = gr.Interface(
|
268 |
+
fn=interact_with_soul,
|
269 |
+
inputs="text",
|
270 |
+
outputs=["text", "text"],
|
271 |
+
title="S.O.U.L AI",
|
272 |
+
description="Enter a prompt to interact with the S.O.U.L AI, which will generate a response and provide an emotional analysis."
|
273 |
+
)
|
274 |
+
iface.launch()
|
275 |
+
|
276 |
+
# Use multiprocessing to utilize all CPU cores
|
277 |
+
if __name__ == '__main__':
|
278 |
+
mp.set_start_method('spawn')
|
279 |
+
p = mp.Process(target=launch_gradio)
|
280 |
+
p.start()
|
281 |
+
p.join()
|