mkoot007 commited on
Commit
be995e6
·
1 Parent(s): 33bf4a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -5,7 +5,7 @@ import torch
5
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
  from easyocr import Reader
7
 
8
- # Load the OCR model and text explanation model (gpt-2 as an example)
9
  ocr_reader = Reader(['en'])
10
  explainer = AutoModelForSequenceClassification.from_pretrained("gpt2")
11
 
@@ -16,10 +16,14 @@ def extract_text(image):
16
  # Define a function to explain the extracted text
17
  def explain_text(text):
18
  tokenizer = AutoTokenizer.from_pretrained("gpt2")
19
-
 
 
 
 
20
  # Encode the text and convert to PyTorch tensors
21
- inputs = tokenizer([text], return_tensors="pt", padding=True, truncation=True, max_length=512)
22
-
23
  input_ids = inputs["input_ids"]
24
  attention_mask = inputs["attention_mask"]
25
 
@@ -36,7 +40,7 @@ uploaded_file = st.file_uploader("Upload an image:")
36
  if uploaded_file is not None:
37
  # Read the uploaded image
38
  image = Image.open(uploaded_file)
39
-
40
  # Process the image and convert to NumPy array if necessary
41
  # image = process_image(image)
42
 
 
5
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
  from easyocr import Reader
7
 
8
+ # Load the OCR model and text explanation model (GPT-2 as an example)
9
  ocr_reader = Reader(['en'])
10
  explainer = AutoModelForSequenceClassification.from_pretrained("gpt2")
11
 
 
16
  # Define a function to explain the extracted text
17
  def explain_text(text):
18
  tokenizer = AutoTokenizer.from_pretrained("gpt2")
19
+
20
+ # Convert the text to a string if necessary
21
+ if not isinstance(text, str):
22
+ text = str(text)
23
+
24
  # Encode the text and convert to PyTorch tensors
25
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
26
+
27
  input_ids = inputs["input_ids"]
28
  attention_mask = inputs["attention_mask"]
29
 
 
40
  if uploaded_file is not None:
41
  # Read the uploaded image
42
  image = Image.open(uploaded_file)
43
+
44
  # Process the image and convert to NumPy array if necessary
45
  # image = process_image(image)
46