Spaces:
Paused
Paused
Samet Yilmaz
commited on
Commit
·
5589f0c
1
Parent(s):
b679c08
Load LLM before gradio
Browse files
app.py
CHANGED
|
@@ -18,6 +18,12 @@ sampling_params = SamplingParams(max_tokens=8192, temperature=0.7)
|
|
| 18 |
max_tokens_per_img = 4096
|
| 19 |
max_img_per_msg = 5
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def encode_image(image: Image.Image, image_format="PNG") -> str:
|
| 22 |
im_file = BytesIO()
|
| 23 |
image.save(im_file, format=image_format)
|
|
@@ -28,13 +34,6 @@ def encode_image(image: Image.Image, image_format="PNG") -> str:
|
|
| 28 |
|
| 29 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 30 |
def infer(image_url, prompt, progress=gr.Progress(track_tqdm=True)):
|
| 31 |
-
# tokenize image urls and text
|
| 32 |
-
llm = LLM(model="mistralai/Pixtral-12B-2409",
|
| 33 |
-
tokenizer_mode="mistral",
|
| 34 |
-
max_model_len=65536,
|
| 35 |
-
max_num_batched_tokens=max_img_per_msg * max_tokens_per_img,
|
| 36 |
-
limit_mm_per_prompt={"image": max_img_per_msg}) # Name or path of your model
|
| 37 |
-
|
| 38 |
image = Image.open(BytesIO(requests.get(image_url).content))
|
| 39 |
image = image.resize((3844, 2408))
|
| 40 |
new_image_url = f"data:image/png;base64,{encode_image(image, image_format='PNG')}"
|
|
|
|
| 18 |
max_tokens_per_img = 4096
|
| 19 |
max_img_per_msg = 5
|
| 20 |
|
| 21 |
+
llm = LLM(model="mistralai/Pixtral-12B-2409",
|
| 22 |
+
tokenizer_mode="mistral",
|
| 23 |
+
max_model_len=65536,
|
| 24 |
+
max_num_batched_tokens=max_img_per_msg * max_tokens_per_img,
|
| 25 |
+
limit_mm_per_prompt={"image": max_img_per_msg}) # Name or path of your model
|
| 26 |
+
|
| 27 |
def encode_image(image: Image.Image, image_format="PNG") -> str:
|
| 28 |
im_file = BytesIO()
|
| 29 |
image.save(im_file, format=image_format)
|
|
|
|
| 34 |
|
| 35 |
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 36 |
def infer(image_url, prompt, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
image = Image.open(BytesIO(requests.get(image_url).content))
|
| 38 |
image = image.resize((3844, 2408))
|
| 39 |
new_image_url = f"data:image/png;base64,{encode_image(image, image_format='PNG')}"
|