sergioska commited on
Commit
aa730c9
·
1 Parent(s): 87a8db4

first commit

Browse files
Files changed (3) hide show
  1. README.md +5 -5
  2. app.py +41 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Flyer Segmenter
3
- emoji: 📈
4
- colorFrom: red
5
- colorTo: green
6
  sdk: streamlit
7
- sdk_version: 1.29.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
+ title: flyer-segmenter
3
+ emoji: 📊
4
+ colorFrom: pink
5
+ colorTo: pink
6
  sdk: streamlit
7
+ sdk_version: 1.28.2
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import streamlit as st
3
+ import numpy as np
4
+ from PIL import Image, ImageDraw
5
+ from transformers import pipeline
6
+ from tempfile import NamedTemporaryFile
7
+
8
+ #detector = pipeline(model="google/owlvit-base-patch32", task="zero-shot-object-detection")
9
+ detector = pipeline("object-detection", model="sergioska/yolo-finetuned-flyers")
10
+
11
+ st.title('Upload an image file to detection')
12
+
13
+ uploaded_image_zero_file = st.file_uploader("Choose an image file (zero)")
14
+ texts = st.text_input('tags')
15
+
16
+ if uploaded_image_zero_file is not None:
17
+ image = Image.open(uploaded_image_zero_file)
18
+ outputImage = np.array(image)
19
+ predictions = detector(
20
+ image,
21
+ candidate_labels=['eggs', 'apple', 'pear']
22
+ )
23
+ st.image(outputImage)
24
+
25
+ if st.button('apply tag'):
26
+ tags = [['products', 'price', 'title']]
27
+
28
+ draw = ImageDraw.Draw(image)
29
+
30
+ for prediction in predictions:
31
+ box = prediction["box"]
32
+ label = prediction["label"]
33
+ score = prediction["score"]
34
+
35
+ xmin, ymin, xmax, ymax = box.values()
36
+ draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=3)
37
+ draw.text((xmin, ymin), f"{label}: {round(score,5)}", fill="white")
38
+
39
+ st.image(image)
40
+ st.write(predictions)
41
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ accelerate
3
+ transformers