Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,30 @@ from PIL import Image
|
|
3 |
from transformers import CLIPProcessor, CLIPModel
|
4 |
|
5 |
# Title of the Streamlit app
|
6 |
-
st.title("
|
7 |
|
8 |
# Load the pre-trained Hugging Face CLIP model
|
9 |
model_name = "openai/clip-vit-base-patch32"
|
10 |
model = CLIPModel.from_pretrained(model_name)
|
11 |
processor = CLIPProcessor.from_pretrained(model_name)
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
|
16 |
-
if
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
image = Image.open(uploaded_file)
|
21 |
-
st.image(image, caption=f"Uploaded Image: {uploaded_file.name}", use_column_width=True)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
inputs = processor(images=image, text=["What is in this image?"], return_tensors="pt")
|
26 |
-
outputs = model(**inputs)
|
27 |
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from transformers import CLIPProcessor, CLIPModel
|
4 |
|
5 |
# Title of the Streamlit app
|
6 |
+
st.title("Product Image Title and Description Generator")
|
7 |
|
8 |
# Load the pre-trained Hugging Face CLIP model
|
9 |
model_name = "openai/clip-vit-base-patch32"
|
10 |
model = CLIPModel.from_pretrained(model_name)
|
11 |
processor = CLIPProcessor.from_pretrained(model_name)
|
12 |
|
13 |
+
# Image upload
|
14 |
+
uploaded_file = st.file_uploader("Upload a product image (JPG, JPEG, PNG):", type=["jpg", "jpeg", "png"])
|
15 |
|
16 |
+
if uploaded_file:
|
17 |
+
# Open and display the uploaded image
|
18 |
+
image = Image.open(uploaded_file)
|
19 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
|
|
|
|
20 |
|
21 |
+
# Process the uploaded image using CLIP model to generate a description
|
22 |
+
st.write("Processing the image...")
|
|
|
|
|
23 |
|
24 |
+
inputs = processor(images=image, text=["What is in this image?"], return_tensors="pt")
|
25 |
+
outputs = model(**inputs)
|
26 |
+
|
27 |
+
# Example output (you can refine the output generation further)
|
28 |
+
generated_description = "This is a stylish jacket suitable for cold weather."
|
29 |
+
|
30 |
+
# Display the generated title and description
|
31 |
+
st.write("Generated Product Title: Stylish Jacket")
|
32 |
+
st.write(f"Generated Product Description: {generated_description}")
|