Spaces:
Runtime error
Runtime error
project init
Browse files- .flake8 +7 -0
- .pre-commit-config.yaml +31 -0
- app.py +28 -0
- poetry.lock +0 -0
- pyproject.toml +29 -0
- requirements.txt +4 -0
.flake8
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[flake8]
|
| 2 |
+
ignore = E203, E266, E501, W503, B904
|
| 3 |
+
# line length is intentionally set to 80 here because black uses Bugbear
|
| 4 |
+
# See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length for more details
|
| 5 |
+
max-line-length = 80
|
| 6 |
+
max-complexity = 18
|
| 7 |
+
select = B, C, E, F, W, T4, B9
|
.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
repos:
|
| 2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
| 3 |
+
rev: v4.2.0
|
| 4 |
+
hooks:
|
| 5 |
+
- id: trailing-whitespace
|
| 6 |
+
args: [--markdown-linebreak-ext=md]
|
| 7 |
+
- id: end-of-file-fixer
|
| 8 |
+
|
| 9 |
+
- repo: https://github.com/asottile/pyupgrade
|
| 10 |
+
rev: v2.32.1
|
| 11 |
+
hooks:
|
| 12 |
+
- id: pyupgrade
|
| 13 |
+
args: [--py39-plus]
|
| 14 |
+
|
| 15 |
+
- repo: https://github.com/pycqa/isort
|
| 16 |
+
rev: 5.10.1
|
| 17 |
+
hooks:
|
| 18 |
+
- id: isort
|
| 19 |
+
args: [--profile=black]
|
| 20 |
+
|
| 21 |
+
- repo: https://github.com/psf/black
|
| 22 |
+
rev: 22.3.0
|
| 23 |
+
hooks:
|
| 24 |
+
- id: black
|
| 25 |
+
|
| 26 |
+
- repo: https://github.com/PyCQA/flake8
|
| 27 |
+
rev: 4.0.1
|
| 28 |
+
hooks:
|
| 29 |
+
- id: flake8
|
| 30 |
+
additional_dependencies:
|
| 31 |
+
- flake8-bugbear
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
from transformers import VisionTextDualEncoderModel, VisionTextDualEncoderProcessor
|
| 7 |
+
from sentence_transformers.util import semantic_search
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
st.title("VitB32 Bert Ko Small Clip Test")
|
| 11 |
+
|
| 12 |
+
model = VisionTextDualEncoderModel.from_pretrained("Bingsu/vitB32_bert_ko_small_clip")
|
| 13 |
+
processor = VisionTextDualEncoderProcessor.from_pretrained(
|
| 14 |
+
"Bingsu/vitB32_bert_ko_small_clip"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
info = pd.read_csv("info.csv")
|
| 18 |
+
with open("img_id.pkl", "rb") as f:
|
| 19 |
+
img_id = pickle.load(f)
|
| 20 |
+
img_emb = np.load("img_emb.npy")
|
| 21 |
+
|
| 22 |
+
text = st.text_input("Input Text")
|
| 23 |
+
tokens = processor(text=text, return_tensors="pt")
|
| 24 |
+
text_emb = model.get_text_features(**tokens)
|
| 25 |
+
|
| 26 |
+
result = semantic_search(text_emb, img_emb, top_k=6)
|
| 27 |
+
|
| 28 |
+
st.write(result)
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tool.poetry]
|
| 2 |
+
name = "vitb32_bert_ko_small_clip_test"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = ""
|
| 5 |
+
authors = ["Bingsu <ks2515@naver.com>"]
|
| 6 |
+
license = "MIT"
|
| 7 |
+
|
| 8 |
+
[tool.poetry.dependencies]
|
| 9 |
+
python = "^3.9"
|
| 10 |
+
torch = "^1.11.0"
|
| 11 |
+
transformers = "^4.19.2"
|
| 12 |
+
streamlit = "^1.10.0"
|
| 13 |
+
pandas = "^1.4.2"
|
| 14 |
+
sentence-transformers = "^2.2.0"
|
| 15 |
+
|
| 16 |
+
[tool.poetry.dev-dependencies]
|
| 17 |
+
black = "^22.3.0"
|
| 18 |
+
isort = "^5.10.1"
|
| 19 |
+
mypy = "^0.961"
|
| 20 |
+
flake8 = "^4.0.1"
|
| 21 |
+
flake8-bugbear = "^22.4.25"
|
| 22 |
+
pre-commit = "^2.19.0"
|
| 23 |
+
|
| 24 |
+
[build-system]
|
| 25 |
+
requires = ["poetry-core>=1.0.0"]
|
| 26 |
+
build-backend = "poetry.core.masonry.api"
|
| 27 |
+
|
| 28 |
+
[tool.isort]
|
| 29 |
+
profile="black"
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
pandas
|
| 4 |
+
sentence-transformers
|