Skip to content

Commit 0daef32

Browse files
committed
fix format
1 parent f7e92e1 commit 0daef32

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

fastchat/constants.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
IMAGE_MODERATION_MSG = (
2626
"$MODERATION$ YOUR IMAGE VIOLATES OUR CONTENT MODERATION GUIDELINES."
2727
)
28-
PDF_MODERATION_MSG = (
29-
"$MODERATION$ YOUR PDF VIOLATES OUR CONTENT MODERATION GUIDELINES."
30-
)
28+
PDF_MODERATION_MSG = "$MODERATION$ YOUR PDF VIOLATES OUR CONTENT MODERATION GUIDELINES."
3129
MODERATION_MSG = "$MODERATION$ YOUR INPUT VIOLATES OUR CONTENT MODERATION GUIDELINES."
3230
CONVERSATION_LIMIT_MSG = "YOU HAVE REACHED THE CONVERSATION LENGTH LIMIT. PLEASE CLEAR HISTORY AND START A NEW CONVERSATION."
3331
INACTIVE_MSG = "THIS SESSION HAS BEEN INACTIVE FOR TOO LONG. PLEASE REFRESH THIS PAGE."

fastchat/serve/gradio_block_arena_vision.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,23 +265,25 @@ def pdf_moderator(images):
265265
import base64
266266
from openai import OpenAI
267267
from io import BytesIO
268-
268+
269269
base64_urls = []
270270
for image in images:
271271
buffer = BytesIO()
272272
image.save(buffer, format="JPEG")
273-
273+
274274
image_bytes = buffer.getvalue()
275275
image_b64 = base64.b64encode(image_bytes).decode("utf-8")
276276

277277
# convert to openai format
278-
base64_urls.append({
279-
"type": "image_url",
280-
"image_url": {
281-
"url": f"data:image/jpeg;base64,{image_b64}",
278+
base64_urls.append(
279+
{
280+
"type": "image_url",
281+
"image_url": {
282+
"url": f"data:image/jpeg;base64,{image_b64}",
283+
},
282284
}
283-
})
284-
285+
)
286+
285287
# OpenAI's maximum number of images is 1 at the moment.
286288
client = OpenAI()
287289
moderations = []
@@ -294,7 +296,7 @@ def pdf_moderator(images):
294296
moderations.append(response[0].results.flagged)
295297
except Exception as e:
296298
print(e)
297-
299+
298300
return all(moderations)
299301

300302

@@ -310,7 +312,7 @@ def detect_language_from_doc(pdf_file_path):
310312

311313
# Convert pdf into image (first page only for efficiency)
312314
images = convert_from_path(pdf_file_path)
313-
315+
314316
extracted_text = pytesseract.image_to_string(
315317
images[0], lang=TESSERACT_SUPPORTED_LANGS
316318
)

fastchat/serve/gradio_block_arena_vision_anony.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,21 +300,13 @@ def add_text(
300300
PDFCHAT_SAMPLING_WEIGHTS,
301301
PDFCHAT_SAMPLING_BOOST_MODELS,
302302
)
303-
303+
304304
# Save an unique id for mapping conversation back to the file on google cloud.
305305
unique_id = hash_pdf(pdfs[0])
306-
306+
307307
states = [
308-
State(
309-
model_left,
310-
is_vision=False,
311-
pdf_id=unique_id
312-
),
313-
State(
314-
model_right,
315-
is_vision=False,
316-
pdf_id=unique_id
317-
),
308+
State(model_left, is_vision=False, pdf_id=unique_id),
309+
State(model_right, is_vision=False, pdf_id=unique_id),
318310
]
319311
upload_pdf_file_to_gcs(
320312
pdf_file_path=pdfs[0],

fastchat/serve/gradio_web_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def __init__(self, model_name, is_vision=False, pdf_id=None):
119119
self.model_name = model_name
120120
self.oai_thread_id = None
121121
self.is_vision = is_vision
122-
self.pdf_id = pdf_id # NOTE(Tim): Version 1 PDFChat Architecture, could be revised later.
122+
self.pdf_id = (
123+
pdf_id # NOTE(Tim): Version 1 PDFChat Architecture, could be revised later.
124+
)
123125

124126
# NOTE(chris): This could be sort of a hack since it assumes the user only uploads one image. If they can upload multiple, we should store a list of image hashes.
125127
self.has_csam_image = False

fastchat/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ def get_pdf_file_from_gcs(filename):
468468

469469
def hash_pdf(file_path):
470470
import hashlib
471-
472-
with open(file_path, 'rb') as f:
471+
472+
with open(file_path, "rb") as f:
473473
file_content = f.read()
474474
return hashlib.md5(file_content).hexdigest()
475475

0 commit comments

Comments
 (0)