xuxw98 commited on
Commit
d0abca8
·
1 Parent(s): 7d52396

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +18 -11
  2. example.json +24 -16
app.py CHANGED
@@ -81,6 +81,10 @@ def instruct_generate(
81
  top_k: The number of top most probable tokens to consider in the sampling process.
82
  temperature: A value controlling the randomness of the sampling process. Higher values result in more random
83
  """
 
 
 
 
84
  sample = {"instruction": prompt, "input": input}
85
  prompt = generate_prompt(sample)
86
  encoded = tokenizer.encode(prompt, bos=True, eos=False, device=model.device)
@@ -103,10 +107,12 @@ def instruct_generate(
103
 
104
  # 配置具体参数
105
  pretrained_path = hf_hub_download(
106
- repo_id="xxw/tapa_model", filename="lit-llama.pth")
107
  tokenizer_path = hf_hub_download(
108
- repo_id="xxw/tapa_model", filename="tokenizer.model")
109
- adapter_path = "lit-llama-adapter-finetuned_15k.pth"
 
 
110
  example_path = "example.json"
111
  # 1024如果不够, 调整为512
112
  max_seq_len = 1024
@@ -117,18 +123,19 @@ tokenizer = Tokenizer(tokenizer_path)
117
  with open(example_path, 'r') as f:
118
  content = f.read()
119
  example_dict = json.loads(content)
120
-
 
 
121
 
122
  def create_instruct_demo():
123
  with gr.Blocks() as instruct_demo:
124
  with gr.Row():
125
  with gr.Column():
126
  scene_img = gr.Image(label='Scene', type='filepath')
127
- object_list = gr.Textbox(
128
- lines=2, label="Input")
129
-
130
  instruction = gr.Textbox(
131
  lines=2, label="Instruction")
 
 
132
  max_len = gr.Slider(minimum=1, maximum=512,
133
  value=128, label="Max length")
134
  with gr.Accordion(label='Advanced options', open=False):
@@ -140,18 +147,18 @@ def create_instruct_demo():
140
  run_botton = gr.Button("Run")
141
 
142
  with gr.Column():
143
- outputs = gr.Textbox(lines=10, label="Output")
144
 
145
- inputs = [instruction, object_list, max_len, top_k, temp]
146
 
147
  # 接下来设定具体的example格式
148
  examples_img_list = glob.glob("caption_demo/*.png")
149
  examples = []
150
  for example_img_one in examples_img_list:
151
  scene_name = os.path.basename(example_img_one).split(".")[0]
152
- example_object_list = example_dict[scene_name]["input"]
153
  example_instruction = example_dict[scene_name]["instruction"]
154
- example_one = [example_img_one, example_object_list, example_instruction, 512, 0.8, 200]
155
  examples.append(example_one)
156
 
157
  gr.Examples(
 
81
  top_k: The number of top most probable tokens to consider in the sampling process.
82
  temperature: A value controlling the randomness of the sampling process. Higher values result in more random
83
  """
84
+ if input in input_value_2_real.keys():
85
+ input = input_value_2_real[input]
86
+ if "..." in input:
87
+ input = input.replace("...", "")
88
  sample = {"instruction": prompt, "input": input}
89
  prompt = generate_prompt(sample)
90
  encoded = tokenizer.encode(prompt, bos=True, eos=False, device=model.device)
 
107
 
108
  # 配置具体参数
109
  pretrained_path = hf_hub_download(
110
+ repo_id="Gary3410/pretrain_lit_llama", filename="lit-llama.pth")
111
  tokenizer_path = hf_hub_download(
112
+ repo_id="Gary3410/tapa_model", filename="tokenizer.model")
113
+ adapter_path = hf_hub_download(
114
+ repo_id="Gary3410/tapa_model", filename="lit-llama-adapter-finetuned_15k.pth")
115
+ # adapter_path = "lit-llama-adapter-finetuned_15k.pth"
116
  example_path = "example.json"
117
  # 1024如果不够, 调整为512
118
  max_seq_len = 1024
 
123
  with open(example_path, 'r') as f:
124
  content = f.read()
125
  example_dict = json.loads(content)
126
+ input_value_2_real = {}
127
+ for scene_id, scene_dict in example_dict.items():
128
+ input_value_2_real[scene_dict["input_display"]] = scene_dict["input"]
129
 
130
  def create_instruct_demo():
131
  with gr.Blocks() as instruct_demo:
132
  with gr.Row():
133
  with gr.Column():
134
  scene_img = gr.Image(label='Scene', type='filepath')
 
 
 
135
  instruction = gr.Textbox(
136
  lines=2, label="Instruction")
137
+ object_list = gr.Textbox(
138
+ lines=5, label="Input")
139
  max_len = gr.Slider(minimum=1, maximum=512,
140
  value=128, label="Max length")
141
  with gr.Accordion(label='Advanced options', open=False):
 
147
  run_botton = gr.Button("Run")
148
 
149
  with gr.Column():
150
+ outputs = gr.Textbox(lines=20, label="Output")
151
 
152
+ inputs = [scene_img, instruction, object_list, max_len, top_k, temp]
153
 
154
  # 接下来设定具体的example格式
155
  examples_img_list = glob.glob("caption_demo/*.png")
156
  examples = []
157
  for example_img_one in examples_img_list:
158
  scene_name = os.path.basename(example_img_one).split(".")[0]
159
+ example_object_list = example_dict[scene_name]["input_display"]
160
  example_instruction = example_dict[scene_name]["instruction"]
161
+ example_one = [example_img_one, example_instruction, example_object_list, 512, 0.8, 200]
162
  examples.append(example_one)
163
 
164
  gr.Examples(
example.json CHANGED
@@ -1,34 +1,42 @@
1
  {
2
  "FloorPlan21": {
3
- "input": "[apple,chair,blender,sink,pottery,oven,egg,table,shredder_(for_paper),seashell,bread,doorknob,fork,plastic_bag,knife,radio_receiver,drawer,person,coffee_maker,inhaler,toaster,plate,cornice,knob,pear,dining_table,tomato,bottle,scale_(measuring_instrument),toilet_tissue,cushion,latch,scissors,soap,handle,balloon,clock,lightbulb,matchbox,refrigerator,trash_can,backpack,alarm_clock,vase,tape_(sticky_cloth_or_paper),printer,cover,faucet,gourd,pan_(for_cooking),ball,spatula,microwave_oven,dispenser,nailfile,cabinet,sweet_potato,lamp,microscope,pot,cup,suitcase,bowl,thermostat,fume_hood,hinge,mirror,spoon,box,]",
4
- "instruction": "Can you clean the dishes?"
 
5
  },
6
  "FloorPlan24": {
7
- "input": "[apple,chair,sink,oven,figurine,shredder_(for_paper),potholder,doorknob,truffle_(chocolate),fork,towel,stove,napkin,knife,drawer,hotplate,coffee_maker,avocado,chopping_board,stool,bolt,toaster,bowling_ball,hand_towel,plate,speaker_(stero_equipment),tag,piggy_bank,knob,dining_table,tomato,scale_(measuring_instrument),toaster_oven,pitcher_(vessel_for_liquid),painting,handle,wineglass,clock,automatic_washer,ice_maker,lightbulb,refrigerator,trash_can,tray,dishwasher,armoire,faucet,gourd,pan_(for_cooking),spatula,microwave_oven,mug,dispenser,cabinet,fire_extinguisher,kitchen_sink,television_set,lamp,cup,bowl,thermostat,water_jug,hinge,spoon,]",
8
- "instruction": "Please make me an omelette."
 
9
  },
10
  "FloorPlan221": {
11
- "input": "[chair,sofa,pen,figurine,table,dog,lampshade,doorknob,bed,toy,drawer,person,statue_(sculpture),flowerpot,stool,monitor_(computer_equipment)computer_monitor,desk,pillow,plate,speaker_(stero_equipment),mouse_(computer_equipment),knob,igniter,dining_table,cushion,painting,dragonfly,laptop_computer,remote_control,vase,trash_can,wall_socket,ashtray,coffee_table,card,computer_keyboard,bird,coaster,television_set,lamp,bowl,thermostat,hinge,curtain,box,]",
12
- "instruction": "Could you please close the curtains?"
 
13
  },
14
  "FloorPlan224": {
15
- "input": "[chair,sofa,figurine,table,crate,necklace,dog,dresser,lampshade,doorknob,horse,frisbee,deer,screwdriver,oil_lamp,drawer,sweater,person,statue_(sculpture),flowerpot,stool,dress,pole,monitor_(computer_equipment)computer_monitor,hat,easel,umbrella,desk,pillow,speaker_(stero_equipment),book,knob,fireplace,ottoman,dining_table,toilet_tissue,cushion,painting,latch,handle,bathtub,laptop_computer,remote_control,clock,lightbulb,candle,vase,trash_can,wall_socket,hose,coffee_table,computer_keyboard,spotlight,bird,cabinet,television_set,lamp,harmonium,cup,thermostat,newspaper,curtain,runner_(carpet),box,]",
16
- "instruction": "Can you turn off the light?"
 
17
  },
18
  "FloorPlan321": {
19
- "input": "[chair,sofa,figurine,table,quilt,bed,lampshade,doorknob,tissue_paper,headboard,button,pencil,drawer,place_mat,cigar_box,knitting_needle,monitor_(computer_equipment)computer_monitor,desk,pillow,chandelier,book,knob,armchair,ottoman,dining_table,notebook,cushion,painting,vent,laptop_computer,blanket,lightbulb,cellular_telephone,trash_can,alarm_clock,tape_(sticky_cloth_or_paper),faucet,card,computer_keyboard,coaster,nailfile,bicycle,mattress,lamp,car_(automobile),magazine,thermostat,heart,mirror,box,]",
20
- "instruction": "Can you please hand me the pencil on the desk?"
 
21
  },
22
  "FloorPlan323": {
23
- "input": "[chair,sofa,sink,dresser,lampshade,bed,doorknob,toy,teddy_bear,towel,headboard,drawer,place_mat,monitor_(computer_equipment)computer_monitor,desk,pillow,speaker_(stero_equipment),mouse_(computer_equipment),piggy_bank,book,cornice,dining_table,cushion,painting,cigarette_case,handle,laptop_computer,remote_control,candle,trash_can,wall_socket,armoire,corkboard,computer_keyboard,lamp,television_set,telephone,cup,hatbox,bowl,thermostat,hinge,mirror,runner_(carpet),box,]",
24
- "instruction": "Can you pass me the remote control, please?"
 
25
  },
26
  "FloorPlan422": {
27
- "input": "[knocker_(on_a_door),sink,hook,clothespin,doorknob,tissue_paper,oil_lamp,drawer,cistern,bottle_cap,desk,hand_towel,knob,bottle,dining_table,toilet_tissue,handle,bathtub,towel_rack,bath_mat,candle_holder,bat_(animal),toilet,wooden_spoon,candle,shower_head,refrigerator,trash_can,cover,hair_dryer,armoire,faucet,scrubbing_brush,dispenser,shower_curtain,cabinet,lamp,bath_towel,cup,thermostat,fume_hood,hinge,mirror,paper_towel,broom,box,]",
28
- "instruction": "Open the Cabinet and give me the Soap Bottle"
 
29
  },
30
  "FloorPlan424": {
31
- "input": "[sink,bucket,doorknob,towel,wine_bucket,cistern,washbasin,pipe,hand_towel,knob,bottle,toilet_tissue,soap,handle,towel_rack,candle_holder,lightbulb,candle,shower_head,crucifix,vase,cover,wall_socket,faucet,scrubbing_brush,dispenser,cabinet,lamp,bath_towel,cup,thermostat,hinge,mirror,toilet,eraser,]",
32
- "instruction": "Please clean the sink"
 
33
  }
34
  }
 
1
  {
2
  "FloorPlan21": {
3
+ "input": "[apple, chair, blender, sink, pottery, oven, egg, table, shredder_(for_paper), seashell, bread, doorknob, fork, plastic_bag, knife, radio_receiver, drawer, person, coffee_maker, inhaler, toaster, plate, cornice, knob, pear, dining_table, tomato, bottle, scale_(measuring_instrument), toilet_tissue, cushion, latch, scissors, soap, handle, balloon, clock, lightbulb, matchbox, refrigerator, trash_can, backpack, alarm_clock, vase, tape_(sticky_cloth_or_paper), printer, cover, faucet, gourd, pan_(for_cooking), ball, spatula, microwave_oven, dispenser, nailfile, cabinet, sweet_potato, lamp, microscope, pot, cup, suitcase, bowl, thermostat, fume_hood, hinge, mirror, spoon, box,]",
4
+ "instruction": "Can you clean the dishes?",
5
+ "input_display": "[apple, chair, blender, sink, pottery, oven, egg, table, shredder_(for_paper), seashell, bread, doorknob, fork, plastic_bag, knife, ...]"
6
  },
7
  "FloorPlan24": {
8
+ "input": "[apple, chair, sink, oven, figurine, shredder_(for_paper), potholder, doorknob, truffle_(chocolate), fork, towel, stove, napkin, knife, drawer, hotplate, coffee_maker, avocado, chopping_board, stool, bolt, toaster, bowling_ball, hand_towel, plate, speaker_(stero_equipment), tag, piggy_bank, knob, dining_table, tomato, scale_(measuring_instrument), toaster_oven, pitcher_(vessel_for_liquid), painting, handle, wineglass, clock, automatic_washer, ice_maker, lightbulb, refrigerator, trash_can, tray, dishwasher, armoire, faucet, gourd, pan_(for_cooking), spatula, microwave_oven, mug, dispenser, cabinet, fire_extinguisher, kitchen_sink, television_set, lamp, cup, bowl, thermostat, water_jug, hinge, spoon,]",
9
+ "instruction": "Please make me an omelette.",
10
+ "input_display": "[apple, chair, sink, oven, figurine, shredder_(for_paper), potholder, doorknob, truffle_(chocolate), fork, towel, stove, napkin, knife, drawer, ...]"
11
  },
12
  "FloorPlan221": {
13
+ "input": "[chair, sofa, pen, figurine, table, dog, lampshade, doorknob, bed, toy, drawer, person, statue_(sculpture), flowerpot, stool, monitor_(computer_equipment)computer_monitor, desk, pillow, plate, speaker_(stero_equipment), mouse_(computer_equipment), knob, igniter, dining_table, cushion, painting, dragonfly, laptop_computer, remote_control, vase, trash_can, wall_socket, ashtray, coffee_table, card, computer_keyboard, bird, coaster, television_set, lamp, bowl, thermostat, hinge, curtain, box,]",
14
+ "instruction": "Could you please close the curtains?",
15
+ "input_display": "[chair, sofa, pen, figurine, table, dog, lampshade, doorknob, bed, toy, drawer, person, statue_(sculpture), flowerpot, stool, ...]"
16
  },
17
  "FloorPlan224": {
18
+ "input": "[chair, sofa, figurine, table, crate, necklace, dog, dresser, lampshade, doorknob, horse, frisbee, deer, screwdriver, oil_lamp, drawer, sweater, person, statue_(sculpture), flowerpot, stool, dress, pole, monitor_(computer_equipment)computer_monitor, hat, easel, umbrella, desk, pillow, speaker_(stero_equipment), book, knob, fireplace, ottoman, dining_table, toilet_tissue, cushion, painting, latch, handle, bathtub, laptop_computer, remote_control, clock, lightbulb, candle, vase, trash_can, wall_socket, hose, coffee_table, computer_keyboard, spotlight, bird, cabinet, television_set, lamp, harmonium, cup, thermostat, newspaper, curtain, runner_(carpet), box,]",
19
+ "instruction": "Can you turn off the light?",
20
+ "input_display": "[chair, sofa, figurine, table, crate, necklace, dog, dresser, lampshade, doorknob, horse, frisbee, deer, screwdriver, oil_lamp, ...]"
21
  },
22
  "FloorPlan321": {
23
+ "input": "[chair, sofa, figurine, table, quilt, bed, lampshade, doorknob, tissue_paper, headboard, button, pencil, drawer, place_mat, cigar_box, knitting_needle, monitor_(computer_equipment)computer_monitor, desk, pillow, chandelier, book, knob, armchair, ottoman, dining_table, notebook, cushion, painting, vent, laptop_computer, blanket, lightbulb, cellular_telephone, trash_can, alarm_clock, tape_(sticky_cloth_or_paper), faucet, card, computer_keyboard, coaster, nailfile, bicycle, mattress, lamp, car_(automobile), magazine, thermostat, heart, mirror, box,]",
24
+ "instruction": "Can you please hand me the pencil on the desk?",
25
+ "input_display": "[chair, sofa, figurine, table, quilt, bed, lampshade, doorknob, tissue_paper, headboard, button, pencil, drawer, place_mat, cigar_box, ...]"
26
  },
27
  "FloorPlan323": {
28
+ "input": "[chair, sofa, sink, dresser, lampshade, bed, doorknob, toy, teddy_bear, towel, headboard, drawer, place_mat, monitor_(computer_equipment)computer_monitor, desk, pillow, speaker_(stero_equipment), mouse_(computer_equipment), piggy_bank, book, cornice, dining_table, cushion, painting, cigarette_case, handle, laptop_computer, remote_control, candle, trash_can, wall_socket, armoire, corkboard, computer_keyboard, lamp, television_set, telephone, cup, hatbox, bowl, thermostat, hinge, mirror, runner_(carpet), box,]",
29
+ "instruction": "Can you pass me the remote control, please?",
30
+ "input_display": "[chair, sofa, sink, dresser, lampshade, bed, doorknob, toy, teddy_bear, towel, headboard, drawer, place_mat, monitor_(computer_equipment)computer_monitor, desk, ...]"
31
  },
32
  "FloorPlan422": {
33
+ "input": "[knocker_(on_a_door), sink, hook, clothespin, doorknob, tissue_paper, oil_lamp, drawer, cistern, bottle_cap, desk, hand_towel, knob, bottle, dining_table, toilet_tissue, handle, bathtub, towel_rack, bath_mat, candle_holder, bat_(animal), toilet, wooden_spoon, candle, shower_head, refrigerator, trash_can, cover, hair_dryer, armoire, faucet, scrubbing_brush, dispenser, shower_curtain, cabinet, lamp, bath_towel, cup, thermostat, fume_hood, hinge, mirror, paper_towel, broom, box,]",
34
+ "instruction": "Open the Cabinet and give me the Soap Bottle",
35
+ "input_display": "[knocker_(on_a_door), sink, hook, clothespin, doorknob, tissue_paper, oil_lamp, drawer, cistern, bottle_cap, desk, hand_towel, knob, bottle, dining_table, ...]"
36
  },
37
  "FloorPlan424": {
38
+ "input": "[sink, bucket, doorknob, towel, wine_bucket, cistern, washbasin, pipe, hand_towel, knob, bottle, toilet_tissue, soap, handle, towel_rack, candle_holder, lightbulb, candle, shower_head, crucifix, vase, cover, wall_socket, faucet, scrubbing_brush, dispenser, cabinet, lamp, bath_towel, cup, thermostat, hinge, mirror, toilet, eraser,]",
39
+ "instruction": "Please clean the sink",
40
+ "input_display": "[sink, bucket, doorknob, towel, wine_bucket, cistern, washbasin, pipe, hand_towel, knob, bottle, toilet_tissue, soap, handle, towel_rack, ...]"
41
  }
42
  }