FlawedLLM commited on
Commit
8febe35
·
verified ·
1 Parent(s): fafb45a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -17,6 +17,12 @@ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda", trust_
17
  processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
18
  model.to("cuda:0")
19
 
 
 
 
 
 
 
20
  PLACEHOLDER = """
21
  <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
22
  <img src="https://cdn-thumbnails.huggingface.co/social-thumbnails/models/microsoft/Phi-3-vision-128k-instruct.png" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
@@ -70,7 +76,8 @@ def bot_streaming(message, history):
70
  conversation.append({"role": "user", "content": message['text']})
71
  print(f"prompt is -\n{conversation}")
72
  prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
73
- image = Image.open(image)
 
74
  inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
75
 
76
  streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})
 
17
  processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
18
  model.to("cuda:0")
19
 
20
+ def base64_to_image(base64_str):
21
+ img_bytes = base64.b64decode(base64_str)
22
+ img_buffer = BytesIO(img_bytes)
23
+ image = Image.open(img_buffer)
24
+ return image
25
+
26
  PLACEHOLDER = """
27
  <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
28
  <img src="https://cdn-thumbnails.huggingface.co/social-thumbnails/models/microsoft/Phi-3-vision-128k-instruct.png" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
 
76
  conversation.append({"role": "user", "content": message['text']})
77
  print(f"prompt is -\n{conversation}")
78
  prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
79
+ # image = Image.open(image)
80
+ image = base64_to_image(image)
81
  inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
82
 
83
  streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})