Spaces:
Runtime error
Runtime error
Upload 10 files
Browse files- .gitattributes +8 -0
- app_test.py +120 -0
- caption_demo/FloorPlan21.png +3 -0
- caption_demo/FloorPlan221.png +3 -0
- caption_demo/FloorPlan224.png +3 -0
- caption_demo/FloorPlan24.png +3 -0
- caption_demo/FloorPlan321.png +3 -0
- caption_demo/FloorPlan323.png +3 -0
- caption_demo/FloorPlan422.png +3 -0
- caption_demo/FloorPlan424.png +3 -0
- example.json +34 -0
.gitattributes
CHANGED
@@ -33,3 +33,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
caption_demo/FloorPlan21.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
caption_demo/FloorPlan221.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
caption_demo/FloorPlan224.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
caption_demo/FloorPlan24.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
caption_demo/FloorPlan321.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
caption_demo/FloorPlan323.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
caption_demo/FloorPlan422.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
caption_demo/FloorPlan424.png filter=lfs diff=lfs merge=lfs -text
|
app_test.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import time
|
3 |
+
import warnings
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
|
7 |
+
# 配置hugface环境
|
8 |
+
from huggingface_hub import hf_hub_download
|
9 |
+
import gradio as gr
|
10 |
+
import os
|
11 |
+
import glob
|
12 |
+
import json
|
13 |
+
|
14 |
+
# os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
|
15 |
+
# torch.set_float32_matmul_precision("high")
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
def instruct_generate(
|
20 |
+
img_path: str = " ",
|
21 |
+
prompt: str = "What food do lamas eat?",
|
22 |
+
input: str = "",
|
23 |
+
max_new_tokens: int = 100,
|
24 |
+
top_k: int = 200,
|
25 |
+
temperature: float = 0.8,
|
26 |
+
) -> None:
|
27 |
+
"""Generates a response based on a given instruction and an optional input.
|
28 |
+
This script will only work with checkpoints from the instruction-tuned LLaMA-Adapter model.
|
29 |
+
See `finetune_adapter.py`.
|
30 |
+
|
31 |
+
Args:
|
32 |
+
prompt: The prompt/instruction (Alpaca style).
|
33 |
+
adapter_path: Path to the checkpoint with trained adapter weights, which are the output of
|
34 |
+
`finetune_adapter.py`.
|
35 |
+
input: Optional input (Alpaca style).
|
36 |
+
pretrained_path: The path to the checkpoint with pretrained LLaMA weights.
|
37 |
+
tokenizer_path: The tokenizer path to load.
|
38 |
+
quantize: Whether to quantize the model and using which method:
|
39 |
+
``"llm.int8"``: LLM.int8() mode,
|
40 |
+
``"gptq.int4"``: GPTQ 4-bit mode.
|
41 |
+
max_new_tokens: The number of generation steps to take.
|
42 |
+
top_k: The number of top most probable tokens to consider in the sampling process.
|
43 |
+
temperature: A value controlling the randomness of the sampling process. Higher values result in more random
|
44 |
+
"""
|
45 |
+
output = [prompt, input, max_new_tokens, top_k, temperature]
|
46 |
+
print(output)
|
47 |
+
return output
|
48 |
+
|
49 |
+
# 配置具体参数
|
50 |
+
|
51 |
+
example_path = "example.json"
|
52 |
+
# 1024如果不够, 调整为512
|
53 |
+
max_seq_len = 1024
|
54 |
+
max_batch_size = 1
|
55 |
+
|
56 |
+
with open(example_path, 'r') as f:
|
57 |
+
content = f.read()
|
58 |
+
example_dict = json.loads(content)
|
59 |
+
|
60 |
+
|
61 |
+
def create_instruct_demo():
|
62 |
+
with gr.Blocks() as instruct_demo:
|
63 |
+
with gr.Row():
|
64 |
+
with gr.Column():
|
65 |
+
scene_img = gr.Image(label='Scene', type='filepath')
|
66 |
+
object_list = gr.Textbox(
|
67 |
+
lines=2, label="Input")
|
68 |
+
|
69 |
+
instruction = gr.Textbox(
|
70 |
+
lines=2, label="Instruction")
|
71 |
+
max_len = gr.Slider(minimum=1, maximum=512,
|
72 |
+
value=128, label="Max length")
|
73 |
+
with gr.Accordion(label='Advanced options', open=False):
|
74 |
+
temp = gr.Slider(minimum=0, maximum=1,
|
75 |
+
value=0.8, label="Temperature")
|
76 |
+
top_k = gr.Slider(minimum=100, maximum=300,
|
77 |
+
value=200, label="Top k")
|
78 |
+
|
79 |
+
run_botton = gr.Button("Run")
|
80 |
+
|
81 |
+
with gr.Column():
|
82 |
+
outputs = gr.Textbox(lines=10, label="Output")
|
83 |
+
|
84 |
+
inputs = [instruction, object_list, max_len, top_k, temp]
|
85 |
+
|
86 |
+
# 接下来设定具体的example格式
|
87 |
+
examples_img_list = glob.glob("caption_demo/*.png")
|
88 |
+
examples = []
|
89 |
+
for example_img_one in examples_img_list:
|
90 |
+
scene_name = os.path.basename(example_img_one).split(".")[0]
|
91 |
+
example_object_list = example_dict[scene_name]["input"]
|
92 |
+
example_instruction = example_dict[scene_name]["instruction"]
|
93 |
+
example_one = [example_img_one, example_object_list, example_instruction, 512, 0.8, 200]
|
94 |
+
examples.append(example_one)
|
95 |
+
|
96 |
+
gr.Examples(
|
97 |
+
examples=examples,
|
98 |
+
inputs=inputs,
|
99 |
+
outputs=outputs,
|
100 |
+
fn=instruct_generate,
|
101 |
+
cache_examples=os.getenv('SYSTEM') == 'spaces'
|
102 |
+
)
|
103 |
+
run_botton.click(fn=instruct_generate, inputs=inputs, outputs=outputs)
|
104 |
+
return instruct_demo
|
105 |
+
|
106 |
+
|
107 |
+
# Please refer to our [arXiv paper](https://arxiv.org/abs/2303.16199) and [github](https://github.com/ZrrSkywalker/LLaMA-Adapter) for more details.
|
108 |
+
description = """
|
109 |
+
# TaPA
|
110 |
+
The official demo for **Embodied Task Planning with Large Language Models**.
|
111 |
+
"""
|
112 |
+
|
113 |
+
with gr.Blocks(css='style.css') as demo:
|
114 |
+
gr.Markdown(description)
|
115 |
+
with gr.TabItem("Instruction-Following"):
|
116 |
+
create_instruct_demo()
|
117 |
+
|
118 |
+
demo.queue(api_open=True, concurrency_count=1).launch()
|
119 |
+
|
120 |
+
|
caption_demo/FloorPlan21.png
ADDED
Git LFS Details
|
caption_demo/FloorPlan221.png
ADDED
Git LFS Details
|
caption_demo/FloorPlan224.png
ADDED
Git LFS Details
|
caption_demo/FloorPlan24.png
ADDED
Git LFS Details
|
caption_demo/FloorPlan321.png
ADDED
Git LFS Details
|
caption_demo/FloorPlan323.png
ADDED
Git LFS Details
|
caption_demo/FloorPlan422.png
ADDED
Git LFS Details
|
caption_demo/FloorPlan424.png
ADDED
Git LFS Details
|
example.json
ADDED
@@ -0,0 +1,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 |
+
},
|
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 |
+
}
|