vithacocf commited on
Commit
8785d5b
·
verified ·
1 Parent(s): 55c8fcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -179,8 +179,9 @@ def handle_file(file, prompt, extra_prompt, max_new_tokens, progress=gr.Progress
179
 
180
  # --- 3. Inference Function ---
181
  @spaces.GPU
182
- def run_inference(img: Image.Image, prompt: str = "", max_new_tokens: int = 512) -> str:
183
  model.to("cuda")
 
184
  if img.mode != "RGB":
185
  img = img.convert("RGB")
186
  prompt_text = prompt.strip()
@@ -199,9 +200,9 @@ def run_inference(img: Image.Image, prompt: str = "", max_new_tokens: int = 512)
199
 
200
  inputs = processor(
201
  text=[text_prompt], images=[img], return_tensors="pt", padding=True
202
- ).to(device)
203
 
204
- with torch.inference_mode(), torch.cuda.amp.autocast(enabled=(device.type == 'cuda')):
205
  gen = model.generate(
206
  **inputs,
207
  max_new_tokens=max_new_tokens,
@@ -215,7 +216,6 @@ def run_inference(img: Image.Image, prompt: str = "", max_new_tokens: int = 512)
215
  )[0].strip()
216
 
217
  return result
218
-
219
  # --- 9. Prompt templates & JSON export ---
220
  prompt_templates = {
221
  "Electrolux": """Extract all structured information from the delivery order document image.
 
179
 
180
  # --- 3. Inference Function ---
181
  @spaces.GPU
182
+ def run_inference(img, prompt="", max_new_tokens=512):
183
  model.to("cuda")
184
+
185
  if img.mode != "RGB":
186
  img = img.convert("RGB")
187
  prompt_text = prompt.strip()
 
200
 
201
  inputs = processor(
202
  text=[text_prompt], images=[img], return_tensors="pt", padding=True
203
+ ).to("cuda") # Sửa ở đây
204
 
205
+ with torch.inference_mode(), torch.cuda.amp.autocast():
206
  gen = model.generate(
207
  **inputs,
208
  max_new_tokens=max_new_tokens,
 
216
  )[0].strip()
217
 
218
  return result
 
219
  # --- 9. Prompt templates & JSON export ---
220
  prompt_templates = {
221
  "Electrolux": """Extract all structured information from the delivery order document image.