Commit
·
479d45f
1
Parent(s):
33db9ac
Update app
Browse files
app.py
CHANGED
|
@@ -118,31 +118,31 @@ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, us
|
|
| 118 |
|
| 119 |
|
| 120 |
def Vintern_1B_v2_ViTable_docvqa(image, question, chat_history=[]):
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
interface = gr.Interface(
|
| 142 |
fn=Vintern_1B_v2_ViTable_docvqa,
|
| 143 |
inputs=[
|
| 144 |
-
gr.Image(label="Upload Image", type="filepath"
|
| 145 |
-
gr.Textbox(label="Enter your question"
|
| 146 |
],
|
| 147 |
outputs=gr.Chatbot(label="Chat History"), # Chatbot-style output
|
| 148 |
title="Vintern-1B-v2-ViTable-docvqa,",
|
|
@@ -150,6 +150,7 @@ interface = gr.Interface(
|
|
| 150 |
allow_flagging="never",
|
| 151 |
)
|
| 152 |
|
|
|
|
| 153 |
# Launch the chatbot
|
| 154 |
interface.launch()
|
| 155 |
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
def Vintern_1B_v2_ViTable_docvqa(image, question, chat_history=[]):
|
| 121 |
+
pixel_values = load_image(image, max_num=12).to(torch.bfloat16).cuda()
|
| 122 |
|
| 123 |
+
generation_config = dict(max_new_tokens= 1024, do_sample=False, num_beams = 3, repetition_penalty=2.0)
|
| 124 |
|
| 125 |
+
# question = input("Question: ")
|
| 126 |
+
question = '<image>\n' + question
|
| 127 |
+
response = model.chat(tokenizer, pixel_values, question, generation_config)
|
| 128 |
+
print(f'User: {question}\nAssistant: {response}')
|
| 129 |
+
print("="*30)
|
| 130 |
|
| 131 |
|
| 132 |
+
# Update the chat history
|
| 133 |
+
chat_history.append((image, None))
|
| 134 |
+
chat_history.append((question, None))
|
| 135 |
+
chat_history.append((None, response))
|
| 136 |
|
| 137 |
+
return chat_history
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
interface = gr.Interface(
|
| 142 |
fn=Vintern_1B_v2_ViTable_docvqa,
|
| 143 |
inputs=[
|
| 144 |
+
gr.Image(label="Upload Image", type="filepath"), # Image input
|
| 145 |
+
gr.Textbox(label="Enter your question"), # Text input
|
| 146 |
],
|
| 147 |
outputs=gr.Chatbot(label="Chat History"), # Chatbot-style output
|
| 148 |
title="Vintern-1B-v2-ViTable-docvqa,",
|
|
|
|
| 150 |
allow_flagging="never",
|
| 151 |
)
|
| 152 |
|
| 153 |
+
|
| 154 |
# Launch the chatbot
|
| 155 |
interface.launch()
|
| 156 |
|