Dua Rajper commited on
Commit
5e4eb8d
·
verified ·
1 Parent(s): 6828d65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
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 CLIPProcessor, CLIPModel
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 model size mismatch
13
  )
14
- processor = CLIPProcessor.from_pretrained("fxmarty/clip-vision-model-tiny")
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
- # ---- Ask a Question About the Image ---- #
50
- user_question = st.text_input("🤖 Ask a question about the image:")
 
 
51
 
52
- if user_question:
53
- with st.spinner("🔍 Analyzing image and generating response..."):
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)")