Spaces:
Runtime error
Runtime error
mohamedemam
commited on
Commit
·
4ac3ef7
1
Parent(s):
998de28
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,17 @@ from transformers import AutoTokenizer
|
|
3 |
import re
|
4 |
from peft import PeftModel, PeftConfig
|
5 |
from transformers import AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
config = PeftConfig.from_pretrained("mohamedemam/Arabic-meeting-summarization")
|
8 |
-
model = AutoModelForCausalLM.from_pretrained("bigscience/bloomz-3b")
|
9 |
model = PeftModel.from_pretrained(model, "mohamedemam/Arabic-meeting-summarization")
|
10 |
# Load the tokenizer and model
|
11 |
model_name ="bigscience/bloomz-3b"
|
@@ -26,7 +34,7 @@ for i in range(len(example_contexts)):
|
|
26 |
# Function to generate questions and answers with configurable parameters
|
27 |
def generate_qa(context, temperature, top_p,num_seq,l_p, num_b):
|
28 |
input_text = context
|
29 |
-
input_ids = tokenizer(input_text, return_tensors='pt')
|
30 |
|
31 |
# Generate with configurable parameters
|
32 |
output = model.generate(
|
@@ -35,7 +43,7 @@ def generate_qa(context, temperature, top_p,num_seq,l_p, num_b):
|
|
35 |
top_p=top_p,
|
36 |
num_return_sequences=num_seq,
|
37 |
|
38 |
-
|
39 |
num_beams=num_b,
|
40 |
length_penalty=l_p,
|
41 |
do_sample=True,
|
@@ -49,7 +57,6 @@ def generate_qa(context, temperature, top_p,num_seq,l_p, num_b):
|
|
49 |
iface = gr.Interface(
|
50 |
fn=generate_qa,
|
51 |
inputs=[
|
52 |
-
gr.inputs.Dropdown(example_contexts, label="Choose an Example"),
|
53 |
gr.inputs.Slider(minimum=0.0, maximum=5, default=2.1, step=0.01, label="Temperature"),
|
54 |
gr.inputs.Slider(minimum=0.0, maximum=1, default=0.5, step=0.01, label="Top-p"),
|
55 |
gr.inputs.Slider(minimum=1, maximum=20, default=3, step=1, label="num of sequance"),
|
|
|
3 |
import re
|
4 |
from peft import PeftModel, PeftConfig
|
5 |
from transformers import AutoModelForCausalLM
|
6 |
+
from transformers import BitsAndBytesConfig
|
7 |
+
|
8 |
+
nf4_config = BitsAndBytesConfig(
|
9 |
+
load_in_4bit=True,
|
10 |
+
bnb_4bit_quant_type="nf4",
|
11 |
+
bnb_4bit_use_double_quant=True,
|
12 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
13 |
+
)
|
14 |
|
15 |
config = PeftConfig.from_pretrained("mohamedemam/Arabic-meeting-summarization")
|
16 |
+
model = AutoModelForCausalLM.from_pretrained("bigscience/bloomz-3b",quantization_config=nf4_config)
|
17 |
model = PeftModel.from_pretrained(model, "mohamedemam/Arabic-meeting-summarization")
|
18 |
# Load the tokenizer and model
|
19 |
model_name ="bigscience/bloomz-3b"
|
|
|
34 |
# Function to generate questions and answers with configurable parameters
|
35 |
def generate_qa(context, temperature, top_p,num_seq,l_p, num_b):
|
36 |
input_text = context
|
37 |
+
input_ids = tokenizer(text=input_text, return_tensors='pt')
|
38 |
|
39 |
# Generate with configurable parameters
|
40 |
output = model.generate(
|
|
|
43 |
top_p=top_p,
|
44 |
num_return_sequences=num_seq,
|
45 |
|
46 |
+
max_new_tokens=60,
|
47 |
num_beams=num_b,
|
48 |
length_penalty=l_p,
|
49 |
do_sample=True,
|
|
|
57 |
iface = gr.Interface(
|
58 |
fn=generate_qa,
|
59 |
inputs=[
|
|
|
60 |
gr.inputs.Slider(minimum=0.0, maximum=5, default=2.1, step=0.01, label="Temperature"),
|
61 |
gr.inputs.Slider(minimum=0.0, maximum=1, default=0.5, step=0.01, label="Top-p"),
|
62 |
gr.inputs.Slider(minimum=1, maximum=20, default=3, step=1, label="num of sequance"),
|