Spaces:
Build error
Build error
CallmeKaito
commited on
Commit
•
ba12792
1
Parent(s):
e67b575
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,34 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import AutoProcessor, AutoModel, VisionEncoderDecoderModel, ViTFeatureExtractor, AutoTokenizer
|
3 |
-
from PIL import Image
|
4 |
import streamlit as st
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
8 |
-
model.load_state_dict(torch.load("model.pth", map_location=torch.device('cpu')))
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values
|
18 |
-
output_ids = model.generate(pixel_values, max_length=100, num_beams=5, early_stopping=True)
|
19 |
-
caption = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0]
|
20 |
-
return caption
|
21 |
|
22 |
-
#
|
23 |
-
def main():
|
24 |
-
st.title("Image Captioning")
|
25 |
-
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
26 |
|
27 |
-
|
28 |
-
image = Image.open(uploaded_file)
|
29 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import io
|
4 |
|
5 |
+
st.title("Artisan Product Submission Form")
|
|
|
|
|
6 |
|
7 |
+
uploaded_file = st.file_uploader("Choose a file", type=["png", "jpg", "jpeg"])
|
8 |
+
|
9 |
+
if uploaded_file is not None:
|
10 |
+
# To read file as bytes:
|
11 |
+
bytes_data = uploaded_file.getvalue()
|
12 |
+
st.write("Filename: ", uploaded_file.name)
|
13 |
+
# st.write(bytes_data) # This will display the raw bytes, typically not useful for users
|
14 |
|
15 |
+
# To display the image
|
16 |
+
image = Image.open(io.BytesIO(bytes_data))
|
17 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
# Creating text input box
|
|
|
|
|
|
|
20 |
|
21 |
+
st.header("Tell us about your product")
|
|
|
|
|
22 |
|
23 |
+
# Input fields
|
24 |
+
product_type = st.text_input("Type of Product", placeholder="e.g., Handmade Jewelry, Pottery, Painting")
|
25 |
+
product_origin = st.text_input("Product Origin", placeholder="e.g., City, Country, Region")
|
26 |
+
product_description = st.text_area("Brief Description", placeholder="Provide a brief description of your product")
|
27 |
|
28 |
+
# Submit button
|
29 |
+
if st.button("Submit"):
|
30 |
+
st.write("Thank you for your submission!")
|
31 |
+
st.write("### Product Details")
|
32 |
+
st.write(f"**Type of Product:** {product_type}")
|
33 |
+
st.write(f"**Product Origin:** {product_origin}")
|
34 |
+
st.write(f"**Description:** {product_description}")
|