Spaces:
Sleeping
Sleeping
Dua Rajper commited on
Update app.py
Browse files
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
|
| 45 |
-
|
| 46 |
-
image_bytes = io.BytesIO(file_bytes)
|
| 47 |
|
| 48 |
-
#
|
| 49 |
with st.spinner("π Extracting text from image..."):
|
| 50 |
-
extracted_text = reader.readtext(
|
| 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:
|