FlawedLLM commited on
Commit
5f4b6cf
·
verified ·
1 Parent(s): 79536dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -19
app.py CHANGED
@@ -16,23 +16,6 @@ model_id = "microsoft/Phi-3-vision-128k-instruct"
16
  model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True, torch_dtype="auto")
17
  processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
18
 
19
- from PIL import Image
20
- import base64
21
- import zlib
22
- from io import BytesIO
23
-
24
- def decode_and_decompress_image(base64_string):
25
- # Decode the Base64 string to bytes
26
- compressed_data = base64.b64decode(base64_string.encode('utf-8'))
27
-
28
- # Decompress the data using zlib
29
- img_bytes = zlib.decompress(compressed_data)
30
-
31
- # Open the image from bytes
32
- img_buffer = BytesIO(img_bytes)
33
- image = Image.open(img_buffer)
34
-
35
- return image
36
 
37
  PLACEHOLDER = """
38
  <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
@@ -87,8 +70,7 @@ def bot_streaming(message, history):
87
  conversation.append({"role": "user", "content": message['text']})
88
  print(f"prompt is -\n{conversation}")
89
  prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
90
- # image = Image.open(image)
91
- image = decode_and_decompress_image(image)
92
  inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
93
 
94
  streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})
 
16
  model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True, torch_dtype="auto")
17
  processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  PLACEHOLDER = """
21
  <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
 
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,})