Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
from transformers.generation import GenerationConfig
|
4 |
import re
|
@@ -15,22 +16,15 @@ from PIL import Image, ImageDraw, UnidentifiedImageError
|
|
15 |
|
16 |
base_url = "https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat"
|
17 |
model_name = "Qwen/Qwen-VL-Chat"
|
18 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
19 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", fp16=True, trust_remote_code=True).eval()
|
20 |
-
model.generation_config = GenerationConfig.from_pretrained(model_name, trust_remote_code=True)
|
21 |
-
|
22 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
23 |
-
model.to(device)
|
24 |
-
task_history = []
|
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 = AutoTokenizer.from_pretrained(
|
32 |
-
self.model = AutoModelForCausalLM.from_pretrained(
|
33 |
-
self.model.generation_config = GenerationConfig.from_pretrained(
|
34 |
self.history = []
|
35 |
|
36 |
def chat(self, image_path=None, text_query=None):
|
|
|
1 |
import gradio as gr
|
2 |
+
import transformers
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
from transformers.generation import GenerationConfig
|
5 |
import re
|
|
|
16 |
|
17 |
base_url = "https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat"
|
18 |
model_name = "Qwen/Qwen-VL-Chat"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
21 |
PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』​``【oaicite:0】``​〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
|
22 |
|
23 |
class ChatBot:
|
24 |
def __init__(self):
|
25 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
26 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", bf16=True, trust_remote_code=True).eval()
|
27 |
+
self.model.generation_config = GenerationConfig.from_pretrained(model_name, trust_remote_code=True)
|
28 |
self.history = []
|
29 |
|
30 |
def chat(self, image_path=None, text_query=None):
|