TobyYang7 commited on
Commit
1736895
·
verified ·
1 Parent(s): 3786aff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -35,28 +35,28 @@ tokenizer, llava_model, image_processor, context_len = load_pretrained_model(
35
  @spaces.GPU
36
  def bot_streaming(message, history):
37
  print(message)
38
- image = None
39
 
40
  # Check if there's an image in the current message
41
  if message["files"]:
42
  # message["files"][-1] could be a dictionary or a string
43
  if isinstance(message["files"][-1], dict):
44
- image = message["files"][-1]["path"]
45
  else:
46
- image = message["files"][-1]
47
  else:
48
- # If no image in the current message, look in the history for the last image
49
  for hist in history:
50
  if isinstance(hist[0], tuple):
51
- image = hist[0][0]
52
 
53
- # Error handling if no image is found
54
- if image is None:
55
  raise gr.Error("You need to upload an image for LLaVA to work.")
56
 
57
- # Load the image if it's a path, otherwise use the existing PIL image
58
- if isinstance(image, str):
59
- image = Image.open(image).convert('RGB')
60
 
61
  # Generate the prompt for the model
62
  prompt = message['text']
@@ -105,7 +105,8 @@ with gr.Blocks(fill_height=True) as demo:
105
  fn=bot_streaming,
106
  title="FinLLaVA",
107
  examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},
108
- {"text": "How to make this pastry?", "files": ["./baklava.png"]}],
 
109
  stop_btn="Stop Generation",
110
  multimodal=True,
111
  textbox=chat_input,
 
35
  @spaces.GPU
36
  def bot_streaming(message, history):
37
  print(message)
38
+ image_path = None
39
 
40
  # Check if there's an image in the current message
41
  if message["files"]:
42
  # message["files"][-1] could be a dictionary or a string
43
  if isinstance(message["files"][-1], dict):
44
+ image_path = message["files"][-1]["path"]
45
  else:
46
+ image_path = message["files"][-1]
47
  else:
48
+ # If no image in the current message, look in the history for the last image path
49
  for hist in history:
50
  if isinstance(hist[0], tuple):
51
+ image_path = hist[0][0]
52
 
53
+ # Error handling if no image path is found
54
+ if image_path is None:
55
  raise gr.Error("You need to upload an image for LLaVA to work.")
56
 
57
+ # If the image_path is a string, no need to load it into a PIL image
58
+ # Just use the path directly in the next steps
59
+ print(f"\033[91m{image_path}, {type(image_path)}\033[0m")
60
 
61
  # Generate the prompt for the model
62
  prompt = message['text']
 
105
  fn=bot_streaming,
106
  title="FinLLaVA",
107
  examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},
108
+ {"text": "How to make this pastry?", "files": ["./baklava.png"]},
109
+ {"text":"What is this?","files":["http://images.cocodataset.org/val2017/000000039769.jpg"]}],
110
  stop_btn="Stop Generation",
111
  multimodal=True,
112
  textbox=chat_input,