thrinadhn commited on
Commit
d3f131e
·
verified ·
1 Parent(s): 7bb9bb2

Update requirements1.txt

Browse files
Files changed (1) hide show
  1. requirements1.txt +58 -1
requirements1.txt CHANGED
@@ -283,4 +283,61 @@ class Florence2:
283
  fp.write(results[task])
284
  fp.write("\n")
285
  fp.write(f"Image Name :: <==> {item}")
286
- fp.write("\n")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  fp.write(results[task])
284
  fp.write("\n")
285
  fp.write(f"Image Name :: <==> {item}")
286
+ fp.write("\n")
287
+
288
+ import copy
289
+ from transformers import AutoProcessor, AutoModelForCausalLM
290
+ from PIL import Image
291
+ import requests
292
+ import utils
293
+
294
+
295
+ model_id = 'microsoft/Florence-2-large'
296
+ model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True).eval().cuda()
297
+ processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
298
+
299
+ utils.set_model_info(model, processor)
300
+
301
+ from google.colab import drive
302
+ drive.mount('/content/drive')
303
+
304
+ path = "/content/pci complliance and Credit card Authorization forms Hand written - Copy.jpg"
305
+
306
+ image = Image.open(path)
307
+ image_rgb = Image.open(path).convert("RGB")
308
+ image
309
+
310
+ img_list = ["/content/images_ocr_image_3.jpg",
311
+ "/content/images_ocr_image_2.jpg",
312
+ "/content/images_ocr_image_1.jpg",
313
+ "/content/images_ocr_image_4.png",
314
+ "/content/pci complliance and Credit card Authorization forms Hand written - Copy.jpg",
315
+ "/content/Charlemagne.png",
316
+ "/content/Frederick II.png",
317
+ "/content/Henry VIII.png",
318
+ "/content/Louis XIV.png",
319
+ "/content/William IV.png",
320
+ "/content/pci complliance and Credit card Authorization forms Hand written - Copy.jpg"
321
+ ]
322
+ for item in img_list:
323
+ path = item
324
+ image = Image.open(path)
325
+ image_rgb = Image.open(path).convert("RGB")
326
+
327
+ tasks = [utils.TaskType.CAPTION,
328
+ utils.TaskType.DETAILED_CAPTION,
329
+ utils.TaskType.MORE_DETAILED_CAPTION,]
330
+
331
+ for task in tasks:
332
+ results = utils.run_example(task, image_rgb)
333
+ print(f'{task.value}{results[task]}')
334
+
335
+ task = utils.TaskType.OCR
336
+ results = utils.run_example(task, image_rgb)
337
+ print('Detected Text: ', results[task])
338
+
339
+ with open("/content/florenecre.txt", "a+" ) as fp:
340
+ fp.write(results[task])
341
+ fp.write("\n")
342
+ fp.write("Image Name :: <==>",item,"==="*30,item)
343
+ fp.write("\n")