MCPcopy Create free account
hub / github.com/T-duality/PillOCR-python / process_image

Method process_image

GPTOCRGUI.py:112–142  ·  view source on GitHub ↗
(self, image)

Source from the content-addressed store, hash-verified

110 self.gpt_model = model_name
111
112 def process_image(self, image):
113 if not self.client:
114 raise Exception("请先设置 API Key 或推理接入点")
115
116 base64_img = f"data:image/png;base64,{self.image_encoder.encode_image(image)}"
117
118 response = self.client.chat.completions.create(
119 model=self.gpt_model,
120 messages=[
121 {
122 "role": "system",
123 "content": self.system_prompt
124 },
125 {
126 "role": "user",
127 "content": [
128 {"type": "text", "text": self.user_prompt},
129 {
130 "type": "image_url",
131 "image_url": {"url": f"{base64_img}"}
132 }
133 ],
134 }
135 ],
136 max_tokens=self.max_tokens,
137 )
138 #debug用
139 #print(response)
140 markdown_content = response.choices[0].message.content
141 markdown_content = re.sub(r'^```markdown\s*\n(.*?)\n```\s*$', r'\1', markdown_content, flags=re.DOTALL)
142 return self.markdown_processor.modify_wrappers(markdown_content)
143
144 def process_clipboard_image(self):
145 if not self.process_pre_exist_image:

Callers 1

Calls 2

encode_imageMethod · 0.80
modify_wrappersMethod · 0.80

Tested by

no test coverage detected