Spaces:
Sleeping
Sleeping
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,16 @@ import streamlit as st
|
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
import easyocr
|
| 5 |
-
from transformers import
|
| 6 |
|
| 7 |
-
# ---- Load CLIP Model ---- #
|
| 8 |
@st.cache_resource
|
| 9 |
def load_clip_model():
|
| 10 |
model = CLIPModel.from_pretrained(
|
| 11 |
"fxmarty/clip-vision-model-tiny",
|
| 12 |
-
ignore_mismatched_sizes=True # Fix
|
| 13 |
)
|
| 14 |
-
processor =
|
| 15 |
return model, processor
|
| 16 |
|
| 17 |
model, processor = load_clip_model()
|
|
@@ -46,13 +46,10 @@ if uploaded_file is not None:
|
|
| 46 |
else:
|
| 47 |
st.warning("No readable text found in the image.")
|
| 48 |
|
| 49 |
-
# ----
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
inputs = processor(text=[user_question], images=image, return_tensors="pt")
|
| 55 |
-
outputs = model.get_image_features(**inputs)
|
| 56 |
-
|
| 57 |
-
st.write("### 🏆 AI Response:")
|
| 58 |
-
st.write("CLIP Model has processed the image! (Further improvements coming soon)")
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
import easyocr
|
| 5 |
+
from transformers import CLIPModel, CLIPImageProcessor
|
| 6 |
|
| 7 |
+
# ---- Load CLIP Model (Vision Only) ---- #
|
| 8 |
@st.cache_resource
|
| 9 |
def load_clip_model():
|
| 10 |
model = CLIPModel.from_pretrained(
|
| 11 |
"fxmarty/clip-vision-model-tiny",
|
| 12 |
+
ignore_mismatched_sizes=True # Fix size mismatch
|
| 13 |
)
|
| 14 |
+
processor = CLIPImageProcessor.from_pretrained("fxmarty/clip-vision-model-tiny")
|
| 15 |
return model, processor
|
| 16 |
|
| 17 |
model, processor = load_clip_model()
|
|
|
|
| 46 |
else:
|
| 47 |
st.warning("No readable text found in the image.")
|
| 48 |
|
| 49 |
+
# ---- Process Image with CLIP Vision Model ---- #
|
| 50 |
+
with st.spinner("🔍 Analyzing image with CLIP Model..."):
|
| 51 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 52 |
+
outputs = model.get_image_features(**inputs)
|
| 53 |
|
| 54 |
+
st.write("### 🏆 AI Response:")
|
| 55 |
+
st.write("CLIP Model has processed the image! (More features coming soon)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|