Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,58 @@
|
|
1 |
import torch
|
2 |
-
from transformers import AutoModel,
|
3 |
import gradio as gr
|
4 |
-
|
|
|
5 |
|
6 |
model = AutoModel.from_pretrained(
|
7 |
"DuckyBlender/racist-phi3",
|
8 |
-
|
9 |
-
torch_dtype=
|
10 |
-
trust_remote_code=True
|
11 |
-
|
12 |
)
|
13 |
tokenizer = AutoTokenizer.from_pretrained("DuckyBlender/racist-phi3")
|
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 |
-
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
from transformers import AutoModel, AutoTokenizer, pipeline
|
3 |
import gradio as gr
|
4 |
+
|
5 |
+
torch.random.manual_seed(0)
|
6 |
|
7 |
model = AutoModel.from_pretrained(
|
8 |
"DuckyBlender/racist-phi3",
|
9 |
+
device_map="auto",
|
10 |
+
torch_dtype="auto",
|
11 |
+
trust_remote_code=True,
|
12 |
+
low_cpu_mem_usage=True,
|
13 |
)
|
14 |
tokenizer = AutoTokenizer.from_pretrained("DuckyBlender/racist-phi3")
|
15 |
+
|
16 |
+
messages = [
|
17 |
+
{"role": "user", "content": "Are you a human?"},
|
18 |
+
{"role": "assistant", "content": "NO DEAR MODERFUCKING NIGGER I AM AN AI MODEL TO FUCK YOU BITCHES"},
|
19 |
+
|
20 |
+
]
|
21 |
+
|
22 |
+
pipe = pipeline(
|
23 |
+
"text-generation",
|
24 |
+
model=model,
|
25 |
+
tokenizer=tokenizer,
|
26 |
+
)
|
27 |
+
|
28 |
+
generation_args = {
|
29 |
+
"max_new_tokens": 256,
|
30 |
+
"return_full_text": False,
|
31 |
+
"temperature": 0.2,
|
32 |
+
"do_sample": True,
|
33 |
+
}
|
34 |
+
def phi3_fun(message,chat_history):
|
35 |
+
messages=[
|
36 |
+
{"role": "user", "content": message},
|
37 |
+
]
|
38 |
+
output = pipe(messages, **generation_args)
|
39 |
+
respond = output[0]['generated_text']
|
40 |
+
return respond
|
41 |
+
|
42 |
+
title = "Chat BiCiTiPi"
|
43 |
+
examples = [
|
44 |
+
'What are you?',
|
45 |
+
"Why am I alive here.",
|
46 |
+
]
|
47 |
+
gr.ChatInterface(
|
48 |
+
fn=phi3_fun,
|
49 |
+
title =title,
|
50 |
+
examples = examples,
|
51 |
+
theme='sudeepshouche/minimalist'
|
52 |
+
).launch(debug=True)
|
53 |
+
# demo = gr.Interface(fn=phi3_fun, inputs="text", outputs="text",title =title,
|
54 |
+
# examples = examples)
|
55 |
+
# demo.launch()
|
56 |
+
|
57 |
+
# output = pipe(messages, **generation_args)
|
58 |
+
# print(output[0]['generated_text'])
|