Dua Rajper commited on
Commit
565d3eb
Β·
verified Β·
1 Parent(s): 2eaadc6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -2,10 +2,11 @@ import streamlit as st
2
  from PIL import Image
3
  import torch
4
  import easyocr
 
5
  import io
6
  from transformers import CLIPModel, CLIPImageProcessor
7
 
8
- # βœ… Fix: set_page_config() must be the first command
9
  st.set_page_config(page_title="Multimodal AI Assistant", layout="wide")
10
 
11
  # ---- Load CLIP Model (Vision Only) ---- #
@@ -13,7 +14,7 @@ st.set_page_config(page_title="Multimodal AI Assistant", layout="wide")
13
  def load_clip_model():
14
  model = CLIPModel.from_pretrained(
15
  "fxmarty/clip-vision-model-tiny",
16
- ignore_mismatched_sizes=True # Fix size mismatch
17
  )
18
  processor = CLIPImageProcessor.from_pretrained("fxmarty/clip-vision-model-tiny")
19
  return model, processor
@@ -36,18 +37,17 @@ uploaded_file = st.file_uploader("πŸ“€ Upload an image", type=["jpg", "png", "jp
36
 
37
  if uploaded_file is not None:
38
  # Convert file to image format
39
- image = Image.open(uploaded_file)
40
 
41
  # βœ… Fix: use `use_container_width` instead of `use_column_width`
42
  st.image(image, caption="Uploaded Image", use_container_width=True)
43
 
44
- # Convert uploaded file to bytes for EasyOCR
45
- file_bytes = uploaded_file.read() # βœ… Fix: Convert file to bytes
46
- image_bytes = io.BytesIO(file_bytes)
47
 
48
- # Extract Text using OCR
49
  with st.spinner("πŸ” Extracting text from image..."):
50
- extracted_text = reader.readtext(image_bytes, detail=0)
51
 
52
  st.write("### πŸ“ Extracted Text:")
53
  if extracted_text:
 
2
  from PIL import Image
3
  import torch
4
  import easyocr
5
+ import numpy as np
6
  import io
7
  from transformers import CLIPModel, CLIPImageProcessor
8
 
9
+ # βœ… Fix: set_page_config() must be the first Streamlit command
10
  st.set_page_config(page_title="Multimodal AI Assistant", layout="wide")
11
 
12
  # ---- Load CLIP Model (Vision Only) ---- #
 
14
  def load_clip_model():
15
  model = CLIPModel.from_pretrained(
16
  "fxmarty/clip-vision-model-tiny",
17
+ ignore_mismatched_sizes=True # βœ… Fix size mismatch
18
  )
19
  processor = CLIPImageProcessor.from_pretrained("fxmarty/clip-vision-model-tiny")
20
  return model, processor
 
37
 
38
  if uploaded_file is not None:
39
  # Convert file to image format
40
+ image = Image.open(uploaded_file).convert("RGB")
41
 
42
  # βœ… Fix: use `use_container_width` instead of `use_column_width`
43
  st.image(image, caption="Uploaded Image", use_container_width=True)
44
 
45
+ # βœ… Convert PIL image to NumPy array for EasyOCR
46
+ image_np = np.array(image)
 
47
 
48
+ # βœ… Fix: Pass the correct format to EasyOCR
49
  with st.spinner("πŸ” Extracting text from image..."):
50
+ extracted_text = reader.readtext(image_np, detail=0)
51
 
52
  st.write("### πŸ“ Extracted Text:")
53
  if extracted_text: