Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,7 @@ DEFAULT_CKPT_PATH = 'qwen/Qwen-VL-Chat'
|
|
16 |
REVISION = 'v1.0.4'
|
17 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
18 |
PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
|
|
|
19 |
|
20 |
def _get_args():
|
21 |
parser = ArgumentParser()
|
@@ -36,10 +37,10 @@ def _get_args():
|
|
36 |
args = parser.parse_args()
|
37 |
return args
|
38 |
|
39 |
-
def handle_image_submission(_chatbot, task_history, file):
|
40 |
if file is None:
|
41 |
-
return _chatbot, task_history
|
42 |
-
file_path = save_image(file)
|
43 |
history_item = ((file_path,), None)
|
44 |
_chatbot.append(history_item)
|
45 |
task_history.append(history_item)
|
@@ -101,7 +102,7 @@ def _parse_text(text):
|
|
101 |
lines[i] = "<br>" + line
|
102 |
text = "".join(lines)
|
103 |
return text
|
104 |
-
def save_image(image_file):
|
105 |
upload_dir = Path(uploaded_file_dir) / "uploads"
|
106 |
upload_dir.mkdir(parents=True, exist_ok=True)
|
107 |
filename = secrets.token_hex(10) + Path(image_file.name).suffix
|
@@ -151,7 +152,7 @@ def _launch_demo(args, model, tokenizer):
|
|
151 |
|
152 |
return _chatbot
|
153 |
|
154 |
-
def save_image(image):
|
155 |
if image is None:
|
156 |
return None
|
157 |
temp_dir = secrets.token_hex(20)
|
|
|
16 |
REVISION = 'v1.0.4'
|
17 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
18 |
PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
|
19 |
+
uploaded_file_dir = os.environ.get("GRADIO_TEMP_DIR") or str(Path(tempfile.gettempdir()) / "gradio")
|
20 |
|
21 |
def _get_args():
|
22 |
parser = ArgumentParser()
|
|
|
37 |
args = parser.parse_args()
|
38 |
return args
|
39 |
|
40 |
+
def handle_image_submission(_chatbot, task_history, file, uploaded_file_dir):
|
41 |
if file is None:
|
42 |
+
return _chatbot, task_history
|
43 |
+
file_path = save_image(file, uploaded_file_dir)
|
44 |
history_item = ((file_path,), None)
|
45 |
_chatbot.append(history_item)
|
46 |
task_history.append(history_item)
|
|
|
102 |
lines[i] = "<br>" + line
|
103 |
text = "".join(lines)
|
104 |
return text
|
105 |
+
def save_image(image_file, uploaded_file_dir):
|
106 |
upload_dir = Path(uploaded_file_dir) / "uploads"
|
107 |
upload_dir.mkdir(parents=True, exist_ok=True)
|
108 |
filename = secrets.token_hex(10) + Path(image_file.name).suffix
|
|
|
152 |
|
153 |
return _chatbot
|
154 |
|
155 |
+
def save_image(image, uploaded_file_dir):
|
156 |
if image is None:
|
157 |
return None
|
158 |
temp_dir = secrets.token_hex(20)
|