Commit
•
2cf4b55
0
Parent(s):
Duplicate from FourthBrainGenAI/MarketMail-AI-Space
Browse filesCo-authored-by: Chris Alexiuk <c-s-ale@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +14 -0
- app.py +44 -0
- requirements.txt +8 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: MarketMail AI Space
|
3 |
+
emoji: 📉
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.27.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: openrail
|
11 |
+
duplicated_from: FourthBrainGenAI/MarketMail-AI-Space
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from peft import PeftModel, PeftConfig
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
peft_model_id = f"FourthBrainGenAI/BLOOMZ-3b-marketmail-ai"
|
6 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
8 |
+
config.base_model_name_or_path,
|
9 |
+
return_dict=True,
|
10 |
+
load_in_8bit=True,
|
11 |
+
device_map="auto",
|
12 |
+
)
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
14 |
+
|
15 |
+
# Load the Lora model
|
16 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
17 |
+
|
18 |
+
|
19 |
+
def make_inference(product, description):
|
20 |
+
batch = tokenizer(
|
21 |
+
f"Below is a product and description, please write a marketing email for this product.\n\n### Product:\n{product}\n### Description:\n{description}\n\n### Marketing Email",
|
22 |
+
return_tensors="pt",
|
23 |
+
)
|
24 |
+
|
25 |
+
with torch.cuda.amp.autocast():
|
26 |
+
output_tokens = model.generate(**batch, max_new_tokens=200)
|
27 |
+
|
28 |
+
return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
|
29 |
+
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
# make a gradio interface
|
33 |
+
import gradio as gr
|
34 |
+
|
35 |
+
gr.Interface(
|
36 |
+
make_inference,
|
37 |
+
[
|
38 |
+
gr.inputs.Textbox(lines=2, label="Product Name"),
|
39 |
+
gr.inputs.Textbox(lines=5, label="Product Description"),
|
40 |
+
],
|
41 |
+
gr.outputs.Textbox(label="Ad"),
|
42 |
+
title="MarketMail-AI",
|
43 |
+
description="MarketMail-AI is a tool that generates marketing emails for products.",
|
44 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
bitsandbytes
|
2 |
+
datasets
|
3 |
+
accelerate
|
4 |
+
loralib
|
5 |
+
gradio
|
6 |
+
git+https://github.com/huggingface/peft.git
|
7 |
+
git+https://github.com/huggingface/transformers.git@main
|
8 |
+
scipy
|