Spaces:
Sleeping
Sleeping
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
# β
Fix: set_page_config() must be the first command
|
| 4 |
-
st.set_page_config(page_title="Multimodal AI Assistant", layout="wide")
|
| 5 |
-
|
| 6 |
from PIL import Image
|
| 7 |
import torch
|
| 8 |
import easyocr
|
|
|
|
| 9 |
from transformers import CLIPModel, CLIPImageProcessor
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# ---- Load CLIP Model (Vision Only) ---- #
|
| 12 |
@st.cache_resource
|
| 13 |
def load_clip_model():
|
|
@@ -35,14 +35,20 @@ st.write("Upload an image and ask a question about it!")
|
|
| 35 |
uploaded_file = st.file_uploader("π€ Upload an image", type=["jpg", "png", "jpeg"])
|
| 36 |
|
| 37 |
if uploaded_file is not None:
|
| 38 |
-
#
|
| 39 |
image = Image.open(uploaded_file)
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Extract Text using OCR
|
| 43 |
with st.spinner("π Extracting text from image..."):
|
| 44 |
-
extracted_text = reader.readtext(
|
| 45 |
-
|
| 46 |
st.write("### π Extracted Text:")
|
| 47 |
if extracted_text:
|
| 48 |
st.success(extracted_text)
|
|
|
|
| 1 |
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) ---- #
|
| 12 |
@st.cache_resource
|
| 13 |
def load_clip_model():
|
|
|
|
| 35 |
uploaded_file = st.file_uploader("π€ Upload an image", type=["jpg", "png", "jpeg"])
|
| 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:
|
| 54 |
st.success(extracted_text)
|