Update app.py
Browse files
app.py
CHANGED
@@ -8,14 +8,6 @@ import torch
|
|
8 |
import argparse
|
9 |
from transformers import AutoModel, AutoTokenizer
|
10 |
|
11 |
-
# README, How to run demo on different devices
|
12 |
-
|
13 |
-
# For Nvidia GPUs.
|
14 |
-
# python web_demo_2.5.py --device cuda
|
15 |
-
|
16 |
-
# For Mac with MPS (Apple silicon or AMD GPUs).
|
17 |
-
# PYTORCH_ENABLE_MPS_FALLBACK=1 python web_demo_2.5.py --device mps
|
18 |
-
|
19 |
# Argparser
|
20 |
parser = argparse.ArgumentParser(description='demo')
|
21 |
parser.add_argument('--device', type=str, default='cuda', help='cuda or mps')
|
@@ -24,7 +16,7 @@ device = args.device
|
|
24 |
assert device in ['cuda', 'mps']
|
25 |
|
26 |
# Load model
|
27 |
-
model_path = 'openbmb/MiniCPM-Llama3-V-
|
28 |
if 'int4' in model_path:
|
29 |
if device == 'mps':
|
30 |
print('Error: running int4 model with bitsandbytes on Mac is not supported right now.')
|
@@ -38,7 +30,7 @@ model.eval()
|
|
38 |
|
39 |
|
40 |
ERROR_MSG = "Error, please retry"
|
41 |
-
model_name = 'MiniCPM-V 2
|
42 |
|
43 |
form_radio = {
|
44 |
'choices': ['Beam Search', 'Sampling'],
|
@@ -222,22 +214,12 @@ def regenerate_button_clicked(_question, _chat_bot, _app_cfg, params_form, num_b
|
|
222 |
|
223 |
with gr.Blocks() as demo:
|
224 |
with gr.Row():
|
225 |
-
with gr.Column(scale=
|
226 |
-
params_form = create_component(form_radio, comp='Radio')
|
227 |
-
with gr.Accordion("Beam Search") as beams_according:
|
228 |
-
num_beams = create_component(num_beams_slider)
|
229 |
-
repetition_penalty = create_component(repetition_penalty_slider)
|
230 |
-
with gr.Accordion("Sampling") as sampling_according:
|
231 |
-
top_p = create_component(top_p_slider)
|
232 |
-
top_k = create_component(top_k_slider)
|
233 |
-
temperature = create_component(temperature_slider)
|
234 |
-
repetition_penalty_2 = create_component(repetition_penalty_slider2)
|
235 |
-
regenerate = create_component({'value': 'Regenerate'}, comp='Button')
|
236 |
-
with gr.Column(scale=3, min_width=500):
|
237 |
app_session = gr.State({'sts':None,'ctx':None,'img':None})
|
238 |
bt_pic = gr.Image(label="Upload an image to start")
|
239 |
-
chat_bot = gr.Chatbot(label=f"Chat with {model_name}")
|
240 |
txt_message = gr.Textbox(label="Input text")
|
|
|
|
|
241 |
|
242 |
regenerate.click(
|
243 |
regenerate_button_clicked,
|
|
|
8 |
import argparse
|
9 |
from transformers import AutoModel, AutoTokenizer
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Argparser
|
12 |
parser = argparse.ArgumentParser(description='demo')
|
13 |
parser.add_argument('--device', type=str, default='cuda', help='cuda or mps')
|
|
|
16 |
assert device in ['cuda', 'mps']
|
17 |
|
18 |
# Load model
|
19 |
+
model_path = 'openbmb/MiniCPM-Llama3-V-2'
|
20 |
if 'int4' in model_path:
|
21 |
if device == 'mps':
|
22 |
print('Error: running int4 model with bitsandbytes on Mac is not supported right now.')
|
|
|
30 |
|
31 |
|
32 |
ERROR_MSG = "Error, please retry"
|
33 |
+
model_name = 'MiniCPM-V 2'
|
34 |
|
35 |
form_radio = {
|
36 |
'choices': ['Beam Search', 'Sampling'],
|
|
|
214 |
|
215 |
with gr.Blocks() as demo:
|
216 |
with gr.Row():
|
217 |
+
with gr.Column(scale=2, min_width=300):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
app_session = gr.State({'sts':None,'ctx':None,'img':None})
|
219 |
bt_pic = gr.Image(label="Upload an image to start")
|
|
|
220 |
txt_message = gr.Textbox(label="Input text")
|
221 |
+
with gr.Column(scale=2, min_width=300):
|
222 |
+
chat_bot = gr.Chatbot(label=f"Chat with {model_name}")
|
223 |
|
224 |
regenerate.click(
|
225 |
regenerate_button_clicked,
|