Flexy0 commited on
Commit
dbd3896
β€’
1 Parent(s): a7d66ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -27
app.py CHANGED
@@ -1,27 +1,45 @@
1
- from transformers import AutoModelForSeq2SeqLM, GPT2Tokenizer
2
- import gradio as gr
3
- # Load your custom tokenizer
4
- custom_tokenizer = GPT2Tokenizer.from_pretrained("athirdpath/DPO_Pairs-Roleplay-Alpaca-NSFW")
5
-
6
- # Load the pre-trained model
7
- model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn", from_tf=True)
8
-
9
- @spaces.GPU
10
- def generate(prompt):
11
- # Tokenize your input using the custom tokenizer
12
- inputs = custom_tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
13
-
14
- # Generate output using the pre-trained model
15
- generated_ids = model.generate(inputs["input_ids"], max_new_tokens=150)
16
-
17
- # Decode the generated output
18
- output = custom_tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
19
-
20
- return output
21
-
22
- input_component = gr.Textbox(label="Input a persona, e.g. photographer", value="photographer")
23
- output_component = gr.Textbox(label="Prompt")
24
- examples = [["Hello!"], ["Are you a chatbot?"]]
25
- description = "This app generates VeoAI Beta Prompts, based on a model trained on a custom dataset."
26
- gr.Interface(generate, inputs=input_component, outputs=output_component, examples=examples, title="VeoAI",
27
- description=description).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Text2TextGenerationPipeline
2
+ from transformers import Trainer, TrainingArguments
3
+ from datasets import load_dataset
4
+
5
+ # Load your custom dataset
6
+ dataset = load_dataset("athirdpath/DPO_Pairs-Roleplay-Alpaca-NSFW")
7
+
8
+ # Load the pre-trained model and tokenizer
9
+ model_name = "facebook/bart-large-cnn"
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
11
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
12
+
13
+ # Define training arguments
14
+ training_args = TrainingArguments(
15
+ output_dir="./veo_small",
16
+ num_train_epochs=3,
17
+ per_device_train_batch_size=4,
18
+ save_steps=10_000,
19
+ save_total_limit=2,
20
+ )
21
+
22
+ # Define Trainer
23
+ trainer = Trainer(
24
+ model=model,
25
+ tokenizer=tokenizer,
26
+ train_dataset=dataset["train"],
27
+ args=training_args,
28
+ )
29
+
30
+ # Train the model
31
+ trainer.train()
32
+
33
+ # Save the fine-tuned model
34
+ model.save_pretrained("./veo_small")
35
+ tokenizer.save_pretrained("./veo_small")
36
+
37
+ # Use the fine-tuned model for generation
38
+ custom_model = AutoModelForSeq2SeqLM.from_pretrained("./veo_small")
39
+ custom_tokenizer = AutoTokenizer.from_pretrained("./veo_small")
40
+ generator = Text2TextGenerationPipeline(model=custom_model, tokenizer=custom_tokenizer)
41
+
42
+ # Example of model usage
43
+ prompt = "Hi"
44
+ output = generator(prompt, max_length=150, num_return_sequences=1)
45
+ print(output[0]["generated_text"])