vilarin commited on
Commit
5cd56f1
1 Parent(s): da420d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -9,7 +9,7 @@ import torch
9
  from PIL import Image
10
  import gradio as gr
11
  import spaces
12
- from transformers import AutoModelForCausalLM, AutoProcessor,TextIteratorStreamer
13
  import os
14
  import time
15
  from huggingface_hub import hf_hub_download
@@ -44,7 +44,6 @@ model = AutoModelForCausalLM.from_pretrained(
44
  trust_remote_code=True
45
  ).to(0)
46
  processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
47
-
48
  eos_token_id=processor.tokenizer.eos_token_id
49
 
50
 
@@ -53,19 +52,19 @@ eos_token_id=processor.tokenizer.eos_token_id
53
  @spaces.GPU(duration=120, queue=False)
54
  def stream_chat(message, history: list, system: str, temperature: float, max_new_tokens: int):
55
  print(message)
56
- conversation = [{"role": "system", "content": system or DEFAULT_SYSTEM}]
57
  for prompt, answer in history:
58
  conversation.extend([{"role": "user", "content": f"<|image_1|>\n{prompt}"}, {"role": "assistant", "content": answer}])
59
  conversation.append({"role": "user", "content": message['text']})
60
 
61
  if message["files"]:
62
- image = Image.open(message["files"][0]).convert('RGB')
63
  else:
64
  image = None
65
 
66
  prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
67
- inputs = processor(prompt, [image], return_tensors="pt").to(0)
68
-
69
  generate_kwargs = dict(
70
  max_new_tokens=max_new_tokens,
71
  temperature=temperature,
 
9
  from PIL import Image
10
  import gradio as gr
11
  import spaces
12
+ from transformers import AutoModelForCausalLM, AutoProcessor, TextIteratorStreamer
13
  import os
14
  import time
15
  from huggingface_hub import hf_hub_download
 
44
  trust_remote_code=True
45
  ).to(0)
46
  processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
 
47
  eos_token_id=processor.tokenizer.eos_token_id
48
 
49
 
 
52
  @spaces.GPU(duration=120, queue=False)
53
  def stream_chat(message, history: list, system: str, temperature: float, max_new_tokens: int):
54
  print(message)
55
+ conversation = [{"role": "user", "content": system or DEFAULT_SYSTEM}]
56
  for prompt, answer in history:
57
  conversation.extend([{"role": "user", "content": f"<|image_1|>\n{prompt}"}, {"role": "assistant", "content": answer}])
58
  conversation.append({"role": "user", "content": message['text']})
59
 
60
  if message["files"]:
61
+ image = Image.open(message["files"][-1]).convert('RGB')
62
  else:
63
  image = None
64
 
65
  prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
66
+ inputs = processor(prompt, images=[image], return_tensors="pt").to(0)
67
+
68
  generate_kwargs = dict(
69
  max_new_tokens=max_new_tokens,
70
  temperature=temperature,