jaydenccc commited on
Commit
89d4483
·
1 Parent(s): ff80f8c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from peft import PeftModel, PeftConfig
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ peft_model_id = f"jaydenccc/AI_Storyteller"
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(synopsis):
20
+ batch = tokenizer(
21
+ f"Below is a one-sentence synopsis, please write a captivating short story based on this synopsis.\n\n### Synopsis:\n{synopsis}\n\n### Short Story:\n", return_tensors='pt',
22
+ )
23
+
24
+ with torch.cuda.amp.autocast():
25
+ output_tokens = model.generate(**batch, max_new_tokens=50)
26
+
27
+ return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
28
+
29
+
30
+ if __name__ == "__main__":
31
+ # make a gradio interface
32
+ import gradio as gr
33
+
34
+ gr.Interface(
35
+ make_inference,
36
+ [
37
+ gr.inputs.Textbox(lines=2, label="Product Name"),
38
+ gr.inputs.Textbox(lines=5, label="Product Description"),
39
+ ],
40
+ gr.outputs.Textbox(label="Ad"),
41
+ title="AI-Storyteller",
42
+ description="AI-Storyteller is a bot that writes short stories given a one sentence synopsis",
43
+ ).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