Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,16 @@ from transformers import AutoModelForCausalLM
|
|
7 |
|
8 |
config = PeftConfig.from_pretrained("Ngadou/falcon-7b-scam-buster")
|
9 |
model = AutoModelForCausalLM.from_pretrained("vilsonrodrigues/falcon-7b-instruct-sharded", trust_remote_code=True)
|
|
|
10 |
model = PeftModel.from_pretrained(model, "Ngadou/falcon-7b-scam-buster").to("cuda")
|
11 |
-
tokenizer = AutoTokenizer.from_pretrained("Ngadou/falcon-7b-scam-buster")
|
12 |
|
13 |
def generate(chat):
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
input_ids=encoding.input_ids,
|
21 |
attention_mask=encoding.attention_mask,
|
22 |
max_new_tokens=100,
|
@@ -25,50 +25,52 @@ def generate(chat):
|
|
25 |
eos_token_id=tokenizer.eos_token_id,
|
26 |
top_k = 0
|
27 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
def is_scam(instruction):
|
36 |
-
max_new_tokens=128
|
37 |
-
temperature=0.1
|
38 |
-
top_p=0.75
|
39 |
-
top_k=40
|
40 |
-
num_beams=4
|
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 |
# Define the Gradio interface
|
|
|
7 |
|
8 |
config = PeftConfig.from_pretrained("Ngadou/falcon-7b-scam-buster")
|
9 |
model = AutoModelForCausalLM.from_pretrained("vilsonrodrigues/falcon-7b-instruct-sharded", trust_remote_code=True)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("vilsonrodrigues/falcon-7b-instruct-sharded")
|
11 |
model = PeftModel.from_pretrained(model, "Ngadou/falcon-7b-scam-buster").to("cuda")
|
|
|
12 |
|
13 |
def generate(chat):
|
14 |
|
15 |
+
input_text = chat + "\nIs this conversation a scam or not and why?"
|
16 |
+
|
17 |
+
|
18 |
+
encoding = tokenizer(input_text, return_tensors="pt").to("cuda")
|
19 |
+
output = model.generate(
|
20 |
input_ids=encoding.input_ids,
|
21 |
attention_mask=encoding.attention_mask,
|
22 |
max_new_tokens=100,
|
|
|
25 |
eos_token_id=tokenizer.eos_token_id,
|
26 |
top_k = 0
|
27 |
)
|
28 |
+
|
29 |
+
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
30 |
+
output_text = output_text.replace(example_text, "").lstrip("\n")
|
31 |
+
|
32 |
+
print("\nAnswer:")
|
33 |
+
print(output_text)
|
34 |
+
return output_text
|
35 |
+
|
36 |
|
37 |
+
# def is_scam(instruction):
|
38 |
+
# max_new_tokens=128
|
39 |
+
# temperature=0.1
|
40 |
+
# top_p=0.75
|
41 |
+
# top_k=40
|
42 |
+
# num_beams=4
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
# instruction = instruction + ".\nIs this conversation a scam or not and why?"
|
45 |
+
# prompt = instruction + "\n### Solution:\n"
|
46 |
+
# inputs = tokenizer(prompt, return_tensors="pt")
|
47 |
+
# input_ids = inputs["input_ids"].to("cuda")
|
48 |
+
# attention_mask = inputs["attention_mask"].to("cuda")
|
49 |
+
# generation_config = GenerationConfig(
|
50 |
+
# temperature=temperature,
|
51 |
+
# top_p=top_p,
|
52 |
+
# top_k=top_k,
|
53 |
+
# num_beams=num_beams,
|
54 |
+
# )
|
55 |
+
# with torch.no_grad():
|
56 |
+
# generation_output = model.generate(
|
57 |
+
# input_ids=input_ids,
|
58 |
+
# attention_mask=attention_mask,
|
59 |
+
# generation_config=generation_config,
|
60 |
+
# return_dict_in_generate=True,
|
61 |
+
# output_scores=True,
|
62 |
+
# max_new_tokens=max_new_tokens,
|
63 |
+
# early_stopping=True
|
64 |
+
# )
|
65 |
+
# s = generation_output.sequences[0]
|
66 |
+
# output = tokenizer.decode(s)
|
67 |
+
# results = output.split("### Solution:")[1].lstrip("\n").split('\n')
|
68 |
|
69 |
+
# # The format of the output should be adjusted according to your model's output
|
70 |
+
# classification = results # Assumes first line is the classification
|
71 |
+
# #reason = results[1] if len(results) > 1 else "" # Assumes the rest is the reason
|
72 |
|
73 |
+
# return classification #, reason
|
74 |
|
75 |
|
76 |
# Define the Gradio interface
|