peterpeter8585 commited on
Commit
3e60930
1 Parent(s): 6130c1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -3
app.py CHANGED
@@ -12,8 +12,50 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
12
  import os
13
  password1=os.environ["password"]
14
  model_id = "peterpeter8585/ai2"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- def respond1(multimodal_input, history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p,password):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  if password==password1:
18
 
19
  images = multimodal_input["files"]
@@ -430,9 +472,19 @@ ae= gr.ChatInterface(
430
 
431
  ],
432
  )
 
 
 
 
 
 
 
 
 
 
 
433
  aa=gr.ChatInterface(
434
  respond1,
435
- textbox=gr.MultimodalTextbox(file_types=["image"], show_label=False),
436
  chatbot=chatbot3,
437
  additional_inputs=[
438
  gr.Textbox(value="You are a helpful assistant.", label="System message", interactive=True),
@@ -482,5 +534,5 @@ ab= gr.ChatInterface(
482
  )
483
  if __name__ == "__main__":
484
  with gr.Blocks(theme="gstaff/xkcd") as ai:
485
- gr.TabbedInterface([aa, ac, ab, ae, aaaa,demo2], ["gpt4(Password needed)", "gpt4(only for programming)", "gpt4(only for medical questions)", "gpt4(only for food recommendations)", "gpt4(only for law questions)","image create"])
486
  ai.launch(share=True)
 
12
  import os
13
  password1=os.environ["password"]
14
  model_id = "peterpeter8585/ai2"
15
+ gr.Interface(
16
+ respond,
17
+ inputs=[gr.MultimodalTextbox(file_types=["image"], show_label=False)],
18
+ outputs="text",
19
+ title="IDEFICS2-8B DPO",
20
+ description="Try IDEFICS2-8B fine-tuned using direct preference optimization (DPO) in this demo. Learn more about vision language model DPO integration of TRL [here](https://huggingface.co/blog/dpo_vlm).",
21
+ examples=[
22
+ {"text": "What is the type of flower in the image and what insect is on it?", "files": ["./bee.jpg"]},
23
+ {"text": "Describe the image", "files": ["./howl.jpg"]},
24
+ ],
25
+ ).launch()def respond1(
26
+ message,
27
+ history: list[tuple[str, str]],
28
+ system_message,
29
+ max_tokens,
30
+ temperature,
31
+ top_p,
32
+ password
33
+ ):
34
+ if password==password1:
35
+ messages = [{"role": "system", "content": "Your name is Chatchat.And your creator of you is Sung Yoon.In Korean, it is 정성윤.These are the instructions for you:"+system_message}]
36
 
37
+ for val in history:
38
+ if val[0]:
39
+ messages.append({"role": "user", "content": val[0]})
40
+ if val[1]:
41
+ messages.append({"role": "assistant", "content": val[1]})
42
+
43
+ messages.append({"role": "user", "content": message})
44
+
45
+ response = ""
46
+
47
+ for message in client.chat_completion(
48
+ messages,
49
+ max_tokens=max_tokens,
50
+ stream=True,
51
+ temperature=temperature,
52
+ top_p=top_p,
53
+ ):
54
+ token = message.choices[0].delta.content
55
+
56
+ response += token
57
+ yield response
58
+ def respond0(multimodal_input, history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p,password):
59
  if password==password1:
60
 
61
  images = multimodal_input["files"]
 
472
 
473
  ],
474
  )
475
+ a7=gr.Interface(
476
+ respond0,
477
+ inputs=[gr.MultimodalTextbox(file_types=["image"], show_label=False)],
478
+ outputs="text",
479
+ title="IDEFICS2-8B DPO",
480
+ description="Try IDEFICS2-8B fine-tuned using direct preference optimization (DPO) in this demo. Learn more about vision language model DPO integration of TRL [here](https://huggingface.co/blog/dpo_vlm).",
481
+ examples=[
482
+ {"text": "What is the type of flower in the image and what insect is on it?", "files": ["./bee.jpg"]},
483
+ {"text": "Describe the image", "files": ["./howl.jpg"]},
484
+ ],
485
+ )
486
  aa=gr.ChatInterface(
487
  respond1,
 
488
  chatbot=chatbot3,
489
  additional_inputs=[
490
  gr.Textbox(value="You are a helpful assistant.", label="System message", interactive=True),
 
534
  )
535
  if __name__ == "__main__":
536
  with gr.Blocks(theme="gstaff/xkcd") as ai:
537
+ gr.TabbedInterface([aa, ac, ab, ae, aaaa,demo2, a7], ["gpt4(Password needed)", "gpt4(only for programming)", "gpt4(only for medical questions)", "gpt4(only for food recommendations)", "gpt4(only for law questions)","image create", "multimodal"])
538
  ai.launch(share=True)