Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,15 +19,17 @@ from PIL import Image as PILImage
|
|
| 19 |
|
| 20 |
base_url = "https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat"
|
| 21 |
model_name = "Qwen/Qwen-VL-Chat"
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
| 24 |
PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』​``【oaicite:0】``​〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
|
| 25 |
|
| 26 |
class ChatBot:
|
| 27 |
def __init__(self):
|
| 28 |
-
self.tokenizer =
|
| 29 |
-
self.model =
|
| 30 |
-
self.model.generation_config = GenerationConfig.from_pretrained(model_name, trust_remote_code=True)
|
| 31 |
self.history = []
|
| 32 |
|
| 33 |
def chat(self, image_path=None, text_query=None):
|
|
@@ -62,7 +64,7 @@ class ChatBot:
|
|
| 62 |
gc.collect()
|
| 63 |
|
| 64 |
def chat_interface(text_query, file):
|
| 65 |
-
chatbot = ChatBot()
|
| 66 |
image_path = file.name if file is not None else None
|
| 67 |
response = chatbot.chat(image_path=image_path, text_query=text_query)
|
| 68 |
|
|
|
|
| 19 |
|
| 20 |
base_url = "https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat"
|
| 21 |
model_name = "Qwen/Qwen-VL-Chat"
|
| 22 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 23 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", bf16=True, trust_remote_code=True).eval()
|
| 24 |
+
model.generation_config = GenerationConfig.from_pretrained(model_name, trust_remote_code=True)
|
| 25 |
|
| 26 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
| 27 |
PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』​``【oaicite:0】``​〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
|
| 28 |
|
| 29 |
class ChatBot:
|
| 30 |
def __init__(self):
|
| 31 |
+
self.tokenizer = tokenizer
|
| 32 |
+
self.model = model
|
|
|
|
| 33 |
self.history = []
|
| 34 |
|
| 35 |
def chat(self, image_path=None, text_query=None):
|
|
|
|
| 64 |
gc.collect()
|
| 65 |
|
| 66 |
def chat_interface(text_query, file):
|
| 67 |
+
chatbot = ChatBot(tokenizer, model)
|
| 68 |
image_path = file.name if file is not None else None
|
| 69 |
response = chatbot.chat(image_path=image_path, text_query=text_query)
|
| 70 |
|