Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
[image_chat] remove decode methods for handling HTTP requests, add to…
Browse files Browse the repository at this point in the history
…rchvision requirements (#4867)

* [image_chat] Support both bytes and string

* update cache key

* Update config.yml

Co-authored-by: Kurt Shuster <kshuster@meta.com>
  • Loading branch information
mqcmd196 and klshuster authored Nov 16, 2022
1 parent be7bc14 commit 0f15b89
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,26 @@ commands:
- setupcuda
- fixgit
- restore_cache:
key: deps-20221031-<< parameters.cachename >>-{{ checksum "requirements.txt" }}
key: deps-20221115-<< parameters.cachename >>-{{ checksum "requirements.txt" }}
- setup
- installdeps
- << parameters.more_installs >>
- save_cache:
key: deps-20221031-<< parameters.cachename >>-{{ checksum "requirements.txt" }}
key: deps-20221115-<< parameters.cachename >>-{{ checksum "requirements.txt" }}
paths:
- "~/venv/bin"
- "~/venv/lib"
- findtests:
marker: << parameters.marker >>
- restore_cache:
key: data-20221031-<< parameters.cachename >>-{{ checksum "teststorun.txt" }}
key: data-20221115-<< parameters.cachename >>-{{ checksum "teststorun.txt" }}
- run:
name: Run tests
no_output_timeout: 60m
command: |
coverage run -m pytest -m << parameters.marker >> << parameters.pytest_flags >> --junitxml=test-results/junit.xml
- save_cache:
key: data-20221031-<< parameters.cachename >>-{{ checksum "teststorun.txt" }}
key: data-20221115-<< parameters.cachename >>-{{ checksum "teststorun.txt" }}
paths:
- "~/ParlAI/data"
- codecov
Expand All @@ -255,12 +255,12 @@ commands:
- checkout
- fixgit
- restore_cache:
key: deps-20221031-bw-{{ checksum "requirements.txt" }}
key: deps-20221115-bw-{{ checksum "requirements.txt" }}
- setup
- installdeps
- installtorchgpu
- save_cache:
key: deps-20221031-bw-{{ checksum "requirements.txt" }}
key: deps-20221115-bw-{{ checksum "requirements.txt" }}
paths:
- "~/venv/bin"
- "~/venv/lib"
Expand Down
22 changes: 16 additions & 6 deletions projects/image_chat/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,25 @@ def interactive_running(self, data):
model act dictionary
"""
reply = {}
reply["text"] = data["personality"][0].decode()
text = data["text"][0].decode()
if type(data["personality"][0]) is bytes:
reply["text"] = data["personality"][0].decode("utf-8")
else:
reply["text"] = data["personality"][0]
if type(data["text"][0]) is bytes:
text = data["text"][0].decode("utf-8")
else:
text = data["text"][0]
if text:
reply["text"] = "\n".join(SHARED["dialog_history"] + [text, reply["text"]])
SHARED["dialog_history"].append(text)
if SHARED["image_feats"] is None:

img_data = str(data["image"][0])
_, encoded = img_data.split(",", 1)
if type(data["image"][0]) is bytes:
img_data = data["image"][0].decode("utf-8")
_, encoded = img_data.split(",", 1)
encoded = encoded[2:-1]
else:
img_data = data["image"][0]
_, encoded = img_data.split(",", 1)
image = Image.open(io.BytesIO(b64decode(encoded))).convert("RGB")
SHARED["image_feats"] = SHARED["image_loader"].extract(image)

Expand All @@ -261,7 +271,7 @@ def do_POST(self):
ctype, pdict = cgi.parse_header(self.headers["content-type"])
pdict["boundary"] = bytes(pdict["boundary"], "utf-8")
postvars = cgi.parse_multipart(self.rfile, pdict)
if postvars["image"][0].decode() != "":
if postvars["image"][0] != "":
SHARED["dialog_history"] = []
SHARED["image_feats"] = None
model_response = self.interactive_running(postvars)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GitPython==3.0.3
hydra-core>=1.1.0
ipython==7.31.1
torch<1.13.0,>=1.4.0
torchvision<0.14.0,>=0.5.0
joblib==1.2.0
nltk==3.6.6
omegaconf>=2.1.1
Expand Down

0 comments on commit 0f15b89

Please sign in to comment.