Update app.py
Browse files
app.py
CHANGED
@@ -5,25 +5,38 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
5 |
|
6 |
peft_model_id = f"mazenlhm/MarketingModel"
|
7 |
config = PeftConfig.from_pretrained(peft_model_id)
|
8 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
9 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
10 |
|
11 |
# Load the Lora model
|
12 |
model = PeftModel.from_pretrained(model, peft_model_id)
|
13 |
|
14 |
-
rom IPython.display import display, Markdown
|
15 |
|
16 |
-
def
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
peft_model_id = f"mazenlhm/MarketingModel"
|
7 |
config = PeftConfig.from_pretrained(peft_model_id)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
config.base_model_name_or_path,
|
10 |
+
return_dict=True,
|
11 |
+
load_in_8bit=True,
|
12 |
+
device_map="auto",
|
13 |
+
)
|
14 |
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
15 |
|
16 |
# Load the Lora model
|
17 |
model = PeftModel.from_pretrained(model, peft_model_id)
|
18 |
|
|
|
19 |
|
20 |
+
def make_inference(product_name, product_description):
|
21 |
+
batch = tokenizer(
|
22 |
+
f"### Product and Description:\n{product_name}: {product_description}\n\n### Ad:",
|
23 |
+
return_tensors="pt",
|
24 |
+
)
|
25 |
|
26 |
+
with torch.cuda.amp.autocast():
|
27 |
+
output_tokens = model.generate(**batch, max_new_tokens=50)
|
28 |
|
29 |
+
return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
gr.Interface(
|
34 |
+
make_inference,
|
35 |
+
[
|
36 |
+
gr.inputs.Textbox(lines=2, label="Product Name"),
|
37 |
+
gr.inputs.Textbox(lines=5, label="Product Description"),
|
38 |
+
],
|
39 |
+
gr.outputs.Textbox(label="Ad"),
|
40 |
+
title="GenerAd-AI",
|
41 |
+
description="GenerAd-AI is a generative model that generates ads for products.",
|
42 |
+
).launch()
|