tungdop2 commited on
Commit
a53340c
·
1 Parent(s): 03cc62f

Add model files with Git LFS

Browse files
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from model import ChallengePromptGenerator
3
+
4
+ model = ChallengePromptGenerator()
5
+
6
+
7
+ def generate(prompt):
8
+ return model.infer_prompt([prompt], max_generation_length=77)[0]
9
+
10
+
11
+ demo = gr.Interface(
12
+ fn=generate,
13
+ inputs=gr.Textbox(
14
+ lines=2,
15
+ value="an image of",
16
+ placeholder="Enter a prompt... ",
17
+ label="Prompt"
18
+ ),
19
+ outputs=gr.Textbox(lines=2, label="Generated Text"),
20
+ title="T2I Prompt Generator",
21
+ examples=[
22
+ ["an image of a cat"],
23
+ ["a picture of a girl"],
24
+ ["a photograph of a mountain"]
25
+ ],
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()
checkpoint-15000/added_tokens.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "</LongCaption>": 50258,
3
+ "<LongCaption>": 50257,
4
+ "<PAD>": 50259
5
+ }
checkpoint-15000/config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "succinctly/text2image-prompt-generator",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "bos_token_id": 50256,
9
+ "embd_pdrop": 0.1,
10
+ "eos_token_id": 50256,
11
+ "initializer_range": 0.02,
12
+ "layer_norm_epsilon": 1e-05,
13
+ "model_type": "gpt2",
14
+ "n_ctx": 1024,
15
+ "n_embd": 768,
16
+ "n_head": 12,
17
+ "n_inner": null,
18
+ "n_layer": 12,
19
+ "n_positions": 1024,
20
+ "reorder_and_upcast_attn": false,
21
+ "resid_pdrop": 0.1,
22
+ "scale_attn_by_inverse_layer_idx": false,
23
+ "scale_attn_weights": true,
24
+ "summary_activation": null,
25
+ "summary_first_dropout": 0.1,
26
+ "summary_proj_to_labels": true,
27
+ "summary_type": "cls_index",
28
+ "summary_use_proj": true,
29
+ "task_specific_params": {
30
+ "text-generation": {
31
+ "do_sample": true,
32
+ "max_length": 50
33
+ }
34
+ },
35
+ "torch_dtype": "float16",
36
+ "transformers_version": "4.43.3",
37
+ "use_cache": true,
38
+ "vocab_size": 50260
39
+ }
checkpoint-15000/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.43.3"
6
+ }
checkpoint-15000/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint-15000/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df6545a8a4b9a368b3783fdcac59c230697fca5daa8dd744c408176902232bd2
3
+ size 248899120
checkpoint-15000/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:863969ceb11b25a11efa54ba947ea3c0d08714d9710bd95e77ca14ac5e9a7772
3
+ size 1385018
checkpoint-15000/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:085ddbfee84141c02b403cccce94ddbc0db883e99e4e7ae5fdbfaa20f1b75777
3
+ size 14244
checkpoint-15000/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:adf5bf452761c234e3daa85a999070bcf12b7ea957b65555b14a80fc069fa45d
3
+ size 1064
checkpoint-15000/special_tokens_map.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<LongCaption>",
3
+ "eos_token": "</LongCaption>",
4
+ "pad_token": "<PAD>",
5
+ "unk_token": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ }
12
+ }
checkpoint-15000/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint-15000/tokenizer_config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": "<LongCaption>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "50258": {
21
+ "content": "</LongCaption>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "50259": {
29
+ "content": "<PAD>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ }
36
+ },
37
+ "bos_token": "<LongCaption>",
38
+ "clean_up_tokenization_spaces": true,
39
+ "eos_token": "</LongCaption>",
40
+ "model_max_length": 1024,
41
+ "pad_token": "<PAD>",
42
+ "tokenizer_class": "GPT2Tokenizer",
43
+ "unk_token": "<|endoftext|>"
44
+ }
checkpoint-15000/trainer_state.json ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint-15000/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d966d8425fcd55b317e293394041be36b2ae7882096bdd70cf0ca1695a8d60ec
3
+ size 5304
checkpoint-15000/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
model.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ from vllm import LLM, SamplingParams
4
+ import logging
5
+
6
+ # Configure logging
7
+ logging.basicConfig(
8
+ level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
9
+ )
10
+ logger = logging.getLogger(__name__)
11
+
12
+ class ChallengePromptGenerator:
13
+ def __init__(
14
+ self,
15
+ model_local_dir="./checkpoint-15000",
16
+ ):
17
+ self.generator = LLM(
18
+ model_local_dir,
19
+ )
20
+
21
+
22
+ def infer_prompt(
23
+ self,
24
+ prompts,
25
+ max_generation_length=77,
26
+ beam_size=1,
27
+ sampling_temperature=0.9,
28
+ sampling_topk=1,
29
+ sampling_topp=1,
30
+ ):
31
+ added_prompts = [f"{self.generator.get_tokenizer().bos_token} {prompt}" for prompt in prompts]
32
+
33
+ sampling_params = SamplingParams(
34
+ max_tokens=max_generation_length,
35
+ temperature=sampling_temperature,
36
+ top_k=sampling_topk,
37
+ top_p=sampling_topp,
38
+ use_beam_search=(beam_size > 1),
39
+ )
40
+
41
+ outputs = self.generator.generate(added_prompts, sampling_params)
42
+ out = []
43
+ for i in range(len(outputs)):
44
+ tmp_out = prompts[i] + outputs[i].outputs[0].text
45
+ # droop last unfished sentence
46
+ if tmp_out[-1] != ".":
47
+ tmp_out = ".".join(tmp_out.split(".")[:-1])
48
+ out.append(tmp_out)
49
+ return out
packages.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gcc-12
2
+ g++-12
3
+ libnuma-dev
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ torch==2.0.0+cpu
3
+ vllm