Vishal1122 commited on
Commit
95176aa
·
verified ·
1 Parent(s): 53275a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -14,10 +14,8 @@ from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, Auto
14
  def save_temp_image(image: Image.Image) -> str:
15
  """
16
  Saves the given PIL Image object as a temporary PNG file.
17
-
18
  Args:
19
  image (Image.Image): The image to be saved.
20
-
21
  Returns:
22
  str: The file path of the saved temporary image.
23
  """
@@ -34,13 +32,13 @@ def id_extractor(image: Image.Image) -> Dict:
34
 
35
  model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
36
 
37
- "Qwen/Qwen2.5-VL-3B-Instruct", torch_dtype="auto", device_map="auto"
38
 
39
  )
40
 
41
  # default processer
42
 
43
- processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct")
44
 
45
  messages = [
46
 
@@ -106,8 +104,9 @@ def id_extractor(image: Image.Image) -> Dict:
106
  generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
107
 
108
  )
109
- return output_text
110
-
 
111
  # Define the Gradio interface for the ID extractor
112
  id_interface = gr.Interface(
113
  fn=id_extractor,
@@ -118,4 +117,4 @@ id_interface = gr.Interface(
118
  )
119
 
120
  # Launch the Gradio interface
121
- id_interface.launch(mcp_server=True)
 
14
  def save_temp_image(image: Image.Image) -> str:
15
  """
16
  Saves the given PIL Image object as a temporary PNG file.
 
17
  Args:
18
  image (Image.Image): The image to be saved.
 
19
  Returns:
20
  str: The file path of the saved temporary image.
21
  """
 
32
 
33
  model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
34
 
35
+ "Qwen/Qwen2.5-VL-7B-Instruct", torch_dtype="auto", device_map="auto"
36
 
37
  )
38
 
39
  # default processer
40
 
41
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
42
 
43
  messages = [
44
 
 
104
  generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
105
 
106
  )
107
+ resp = output_text[-1].replace("```json", "").replace("```", "").strip()
108
+ return json.loads(resp)
109
+
110
  # Define the Gradio interface for the ID extractor
111
  id_interface = gr.Interface(
112
  fn=id_extractor,
 
117
  )
118
 
119
  # Launch the Gradio interface
120
+ id_interface.launch(mcp_server=True)