fl399 commited on
Commit
f2216d5
1 Parent(s): 56f3b9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -45
app.py CHANGED
@@ -66,54 +66,54 @@ A: Let's find the row of year 2007, that's Row 3. Let's extract the numbers on R
66
 
67
  ## alpaca-lora
68
 
69
- assert (
70
- "LlamaTokenizer" in transformers._import_structure["models.llama"]
71
- ), "LLaMA is now in HuggingFace's main branch.\nPlease reinstall it: pip uninstall transformers && pip install git+https://github.com/huggingface/transformers.git"
72
- from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
73
 
74
- tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
75
 
76
- BASE_MODEL = "decapoda-research/llama-7b-hf"
77
- LORA_WEIGHTS = "tloen/alpaca-lora-7b"
78
 
79
- if device == "cuda":
80
- model = LlamaForCausalLM.from_pretrained(
81
- BASE_MODEL,
82
- load_in_8bit=False,
83
- torch_dtype=torch.float16,
84
- device_map="auto",
85
- )
86
- model = PeftModel.from_pretrained(
87
- model, LORA_WEIGHTS, torch_dtype=torch.float16, force_download=True
88
- )
89
- elif device == "mps":
90
- model = LlamaForCausalLM.from_pretrained(
91
- BASE_MODEL,
92
- device_map={"": device},
93
- torch_dtype=torch.float16,
94
- )
95
- model = PeftModel.from_pretrained(
96
- model,
97
- LORA_WEIGHTS,
98
- device_map={"": device},
99
- torch_dtype=torch.float16,
100
- )
101
- else:
102
- model = LlamaForCausalLM.from_pretrained(
103
- BASE_MODEL, device_map={"": device}, low_cpu_mem_usage=True
104
- )
105
- model = PeftModel.from_pretrained(
106
- model,
107
- LORA_WEIGHTS,
108
- device_map={"": device},
109
- )
110
 
111
 
112
- if device != "cpu":
113
- model.half()
114
- model.eval()
115
- if torch.__version__ >= "2":
116
- model = torch.compile(model)
117
 
118
 
119
  ## FLAN-UL2
@@ -223,10 +223,17 @@ theme = gr.themes.Monochrome(
223
 
224
  with gr.Blocks(theme=theme) as demo:
225
  with gr.Column():
 
 
 
 
 
 
 
226
  gr.Markdown(
227
  """<h1><center>DePlot+LLM: Multimodal chain-of-thought reasoning on plots</center></h1>
228
  <p>
229
- This is a demo of DePlot+LLM for QA and summarisation. <a href='https://arxiv.org/abs/2212.10505' target='_blank'>DePlot</a> is an image-to-text model that converts plots and charts into a textual sequence. The sequence then is used to prompt LLM for chain-of-thought reasoning. The current underlying LLMs are <a href='https://huggingface.co/spaces/tloen/alpaca-lora' target='_blank'>alpaca-lora</a>, <a href='https://huggingface.co/google/flan-ul2' target='_blank'>flan-ul2</a>, and <a href='https://openai.com/blog/chatgpt' target='_blank'>gpt-3.5-turbo</a>. To use it, simply upload your image and type a question or instruction and click 'submit', or click one of the examples to load them. Read more at the links below.
230
  </p>
231
  """
232
  )
@@ -236,7 +243,8 @@ with gr.Blocks(theme=theme) as demo:
236
  input_image = gr.Image(label="Input Image", type="pil", interactive=True)
237
  #input_image.style(height=512, width=512)
238
  instruction = gr.Textbox(placeholder="Enter your instruction/question...", label="Question/Instruction")
239
- llm = gr.Dropdown(["alpaca-lora", "flan-ul2", "gpt-3.5-turbo"], label="LLM")
 
240
  openai_api_key_textbox = gr.Textbox(value='',
241
  placeholder="Paste your OpenAI API key (sk-...) and hit Enter (if using OpenAI models, otherwise leave empty)",
242
  show_label=False, lines=1, type='password')
 
66
 
67
  ## alpaca-lora
68
 
69
+ # assert (
70
+ # "LlamaTokenizer" in transformers._import_structure["models.llama"]
71
+ # ), "LLaMA is now in HuggingFace's main branch.\nPlease reinstall it: pip uninstall transformers && pip install git+https://github.com/huggingface/transformers.git"
72
+ # from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
73
 
74
+ # tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
75
 
76
+ # BASE_MODEL = "decapoda-research/llama-7b-hf"
77
+ # LORA_WEIGHTS = "tloen/alpaca-lora-7b"
78
 
79
+ # if device == "cuda":
80
+ # model = LlamaForCausalLM.from_pretrained(
81
+ # BASE_MODEL,
82
+ # load_in_8bit=False,
83
+ # torch_dtype=torch.float16,
84
+ # device_map="auto",
85
+ # )
86
+ # model = PeftModel.from_pretrained(
87
+ # model, LORA_WEIGHTS, torch_dtype=torch.float16, force_download=True
88
+ # )
89
+ # elif device == "mps":
90
+ # model = LlamaForCausalLM.from_pretrained(
91
+ # BASE_MODEL,
92
+ # device_map={"": device},
93
+ # torch_dtype=torch.float16,
94
+ # )
95
+ # model = PeftModel.from_pretrained(
96
+ # model,
97
+ # LORA_WEIGHTS,
98
+ # device_map={"": device},
99
+ # torch_dtype=torch.float16,
100
+ # )
101
+ # else:
102
+ # model = LlamaForCausalLM.from_pretrained(
103
+ # BASE_MODEL, device_map={"": device}, low_cpu_mem_usage=True
104
+ # )
105
+ # model = PeftModel.from_pretrained(
106
+ # model,
107
+ # LORA_WEIGHTS,
108
+ # device_map={"": device},
109
+ # )
110
 
111
 
112
+ # if device != "cpu":
113
+ # model.half()
114
+ # model.eval()
115
+ # if torch.__version__ >= "2":
116
+ # model = torch.compile(model)
117
 
118
 
119
  ## FLAN-UL2
 
223
 
224
  with gr.Blocks(theme=theme) as demo:
225
  with gr.Column():
226
+ # gr.Markdown(
227
+ # """<h1><center>DePlot+LLM: Multimodal chain-of-thought reasoning on plots</center></h1>
228
+ # <p>
229
+ # This is a demo of DePlot+LLM for QA and summarisation. <a href='https://arxiv.org/abs/2212.10505' target='_blank'>DePlot</a> is an image-to-text model that converts plots and charts into a textual sequence. The sequence then is used to prompt LLM for chain-of-thought reasoning. The current underlying LLMs are <a href='https://huggingface.co/spaces/tloen/alpaca-lora' target='_blank'>alpaca-lora</a>, <a href='https://huggingface.co/google/flan-ul2' target='_blank'>flan-ul2</a>, and <a href='https://openai.com/blog/chatgpt' target='_blank'>gpt-3.5-turbo</a>. To use it, simply upload your image and type a question or instruction and click 'submit', or click one of the examples to load them. Read more at the links below.
230
+ # </p>
231
+ # """
232
+ # )
233
  gr.Markdown(
234
  """<h1><center>DePlot+LLM: Multimodal chain-of-thought reasoning on plots</center></h1>
235
  <p>
236
+ This is a demo of DePlot+LLM for QA and summarisation. <a href='https://arxiv.org/abs/2212.10505' target='_blank'>DePlot</a> is an image-to-text model that converts plots and charts into a textual sequence. The sequence then is used to prompt LLM for chain-of-thought reasoning. The current underlying LLMs are <a href='https://huggingface.co/google/flan-ul2' target='_blank'>flan-ul2</a> and <a href='https://openai.com/blog/chatgpt' target='_blank'>gpt-3.5-turbo</a>. To use it, simply upload your image and type a question or instruction and click 'submit', or click one of the examples to load them. Read more at the links below.
237
  </p>
238
  """
239
  )
 
243
  input_image = gr.Image(label="Input Image", type="pil", interactive=True)
244
  #input_image.style(height=512, width=512)
245
  instruction = gr.Textbox(placeholder="Enter your instruction/question...", label="Question/Instruction")
246
+ #llm = gr.Dropdown(["alpaca-lora", "flan-ul2", "gpt-3.5-turbo"], label="LLM")
247
+ llm = gr.Dropdown(["flan-ul2", "gpt-3.5-turbo"], label="LLM")
248
  openai_api_key_textbox = gr.Textbox(value='',
249
  placeholder="Paste your OpenAI API key (sk-...) and hit Enter (if using OpenAI models, otherwise leave empty)",
250
  show_label=False, lines=1, type='password')