Spaces:
Runtime error
Runtime error
add application file
Browse files- app.py +39 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from peft import PeftModel, PeftConfig
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
peft_model_id = f"martomor/oasis-bloom"
|
| 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 |
+
def make_inference(song_name):
|
| 19 |
+
batch = tokenizer(f"### song name:\n{song_name}: \n### lyrics:\n", return_tensors='pt')
|
| 20 |
+
|
| 21 |
+
with torch.cuda.amp.autocast():
|
| 22 |
+
output_tokens = model.generate(**batch, max_new_tokens=50)
|
| 23 |
+
|
| 24 |
+
return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
# make a gradio interface
|
| 29 |
+
import gradio as gr
|
| 30 |
+
|
| 31 |
+
gr.Interface(
|
| 32 |
+
make_inference,
|
| 33 |
+
[
|
| 34 |
+
gr.inputs.Textbox(lines=2, label="Song name"),
|
| 35 |
+
],
|
| 36 |
+
gr.outputs.Textbox(label="Song"),
|
| 37 |
+
title="Oasis-Bloom",
|
| 38 |
+
description="Oasis-Bloomis a generative model that generates Oasis lyrics.",
|
| 39 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|