Tonic commited on
Commit
36c55b1
·
unverified ·
1 Parent(s): c6cb576

add Pixtral

Browse files
Files changed (1) hide show
  1. app.py +3 -18
app.py CHANGED
@@ -38,23 +38,11 @@ with open(f'{model_path}/params.json', 'r') as f:
38
  with open(f'{model_path}/tekken.json', 'r') as f:
39
  tokenizer_config = json.load(f)
40
 
41
- @spaces.GPU()
42
- def initialize_llm():
43
- try:
44
- llm = LLM(
45
- model=repo_id,
46
- tokenizer_mode="mistral",
47
- max_model_len=65536,
48
- max_num_batched_tokens=max_img_per_msg * max_tokens_per_img,
49
- limit_mm_per_prompt={"image": max_img_per_msg}
50
- )
51
- return llm
52
- except Exception as e:
53
- print("LLM initialization failed:", e)
54
- return None
55
 
56
  sampling_params = SamplingParams(max_tokens=8192)
57
- llm = initialize_llm()
 
58
 
59
  def encode_image(image: Image.Image, image_format="PNG") -> str:
60
  im_file = BytesIO()
@@ -63,7 +51,6 @@ def encode_image(image: Image.Image, image_format="PNG") -> str:
63
  im_64 = base64.b64encode(im_bytes).decode("utf-8")
64
  return im_64
65
 
66
- @spaces.GPU()
67
  def infer(image_url, prompt, progress=gr.Progress(track_tqdm=True)):
68
  if llm is None:
69
  return "Error: LLM initialization failed. Please try again later."
@@ -86,7 +73,6 @@ def infer(image_url, prompt, progress=gr.Progress(track_tqdm=True)):
86
  except Exception as e:
87
  return f"Error during inference: {e}"
88
 
89
- @spaces.GPU()
90
  def compare_images(image1_url, image2_url, prompt, progress=gr.Progress(track_tqdm=True)):
91
  if llm is None:
92
  return "Error: LLM initialization failed. Please try again later."
@@ -116,7 +102,6 @@ def compare_images(image1_url, image2_url, prompt, progress=gr.Progress(track_tq
116
  except Exception as e:
117
  return f"Error during image comparison: {e}"
118
 
119
- @spaces.GPU()
120
  def calculate_image_similarity(image1_url, image2_url):
121
  if llm is None:
122
  return "Error: LLM initialization failed. Please try again later."
 
38
  with open(f'{model_path}/tekken.json', 'r') as f:
39
  tokenizer_config = json.load(f)
40
 
41
+ model_name = "mistralai/Pixtral-12B-2409"
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  sampling_params = SamplingParams(max_tokens=8192)
44
+
45
+ llm = LLM(model=model_name, tokenizer_mode="mistral")
46
 
47
  def encode_image(image: Image.Image, image_format="PNG") -> str:
48
  im_file = BytesIO()
 
51
  im_64 = base64.b64encode(im_bytes).decode("utf-8")
52
  return im_64
53
 
 
54
  def infer(image_url, prompt, progress=gr.Progress(track_tqdm=True)):
55
  if llm is None:
56
  return "Error: LLM initialization failed. Please try again later."
 
73
  except Exception as e:
74
  return f"Error during inference: {e}"
75
 
 
76
  def compare_images(image1_url, image2_url, prompt, progress=gr.Progress(track_tqdm=True)):
77
  if llm is None:
78
  return "Error: LLM initialization failed. Please try again later."
 
102
  except Exception as e:
103
  return f"Error during image comparison: {e}"
104
 
 
105
  def calculate_image_similarity(image1_url, image2_url):
106
  if llm is None:
107
  return "Error: LLM initialization failed. Please try again later."