natalis3405 commited on
Commit
a3feeee
·
1 Parent(s): 5f3399c
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -1,6 +1,20 @@
1
  import gradio as gr
2
  from PIL import Image
3
  import pytesseract
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  # Function to process image and extract text
6
  def extract_text_from_image(image):
@@ -29,7 +43,7 @@ def extract_text_from_image(image):
29
  """
30
 
31
  # Return results
32
- return extracted_text, img, status
33
 
34
  except Exception as e:
35
  error_status = f"""
 
1
  import gradio as gr
2
  from PIL import Image
3
  import pytesseract
4
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
5
+
6
+ model_name = "google/flan-t5-base"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
9
+
10
+ def process_text(text)
11
+ text = text
12
+ prompt = f"Extract name, dob, license_number, expiry, address from the following text and return JSON:\n{text}"
13
+
14
+ inputs = tokenizer(prompt, return_tensors="pt", max_length=1024, truncation=True)
15
+ outputs = model.generate(**inputs, max_length=256)
16
+ json_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
17
+ print(json_text)
18
 
19
  # Function to process image and extract text
20
  def extract_text_from_image(image):
 
43
  """
44
 
45
  # Return results
46
+ return process_text(extracted_text), img, status
47
 
48
  except Exception as e:
49
  error_status = f"""