cyrus28214 commited on
Commit
600f2a3
·
unverified ·
1 Parent(s): b8c03bf
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -12,11 +12,22 @@ model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
12
  )
13
 
14
  @spaces.GPU
15
- def respond(input_dict, history):
 
 
 
 
 
 
 
16
  text = input_dict["text"]
17
  files = input_dict["files"]
18
 
19
- messages = [
 
 
 
 
20
  {
21
  "role": "user",
22
  "content": [
@@ -24,7 +35,7 @@ def respond(input_dict, history):
24
  *[{"type": "image", "image": image} for image in files]
25
  ]
26
  }
27
- ]
28
  image_inputs, video_inputs = process_vision_info(messages)
29
  prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
30
  inputs = processor(
@@ -36,7 +47,7 @@ def respond(input_dict, history):
36
  ).to(model.device)
37
 
38
  streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)
39
- generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
40
 
41
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
42
  thread.start()
@@ -50,6 +61,18 @@ demo = gr.ChatInterface(
50
  fn=respond,
51
  type='messages',
52
  multimodal=True,
 
 
 
 
 
 
 
 
 
 
 
 
53
  )
54
 
55
  demo.launch(debug=True)
 
12
  )
13
 
14
  @spaces.GPU
15
+ def respond(
16
+ input_dict,
17
+ chat_history,
18
+ system_message,
19
+ max_tokens,
20
+ temperature,
21
+ top_p,
22
+ ):
23
  text = input_dict["text"]
24
  files = input_dict["files"]
25
 
26
+ messages = [{
27
+ "role": "system",
28
+ "content": system_message
29
+ }]
30
+ messages.append(
31
  {
32
  "role": "user",
33
  "content": [
 
35
  *[{"type": "image", "image": image} for image in files]
36
  ]
37
  }
38
+ )
39
  image_inputs, video_inputs = process_vision_info(messages)
40
  prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
41
  inputs = processor(
 
47
  ).to(model.device)
48
 
49
  streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)
50
+ generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=max_tokens, temperature=temperature, top_p=top_p)
51
 
52
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
53
  thread.start()
 
61
  fn=respond,
62
  type='messages',
63
  multimodal=True,
64
+ additional_inputs=[
65
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
66
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
67
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
68
+ gr.Slider(
69
+ minimum=0.1,
70
+ maximum=1.0,
71
+ value=0.95,
72
+ step=0.05,
73
+ label="Top-p (nucleus sampling)",
74
+ ),
75
+ ],
76
  )
77
 
78
  demo.launch(debug=True)