peterpeter8585 commited on
Commit
539cece
1 Parent(s): 777a944

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -16
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import numpy as np
3
- from Ai import chatbot, chatbot2, chatbot3, chatbot4, chatbot5
4
  from huggingface_hub import InferenceClient
5
  def chat(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p, top_k):
6
  m=AutoModel.from_pretrained("peterpeter8585/AI1")
@@ -24,7 +24,9 @@ import random
24
  from diffusers import DiffusionPipeline
25
  import torch
26
  import transformers
27
-
 
 
28
  from transformers import BitsAndBytesConfig
29
 
30
  quantization_config = BitsAndBytesConfig(
@@ -35,7 +37,23 @@ quantization_config = BitsAndBytesConfig(
35
  )
36
 
37
 
 
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  from transformers import AutoModelForVision2Seq, AutoProcessor
40
  transformers.utils.move_cache()
41
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -77,10 +95,8 @@ def respond1(
77
  yield response
78
  def respond0(multimodal_input,password):
79
  if password==password1:
80
- if multimodal_input["files"] =! None:
81
- images = multimodal_input["files"]
82
- content = [{"type": "image"} for _ in images]
83
- content.append({"type": "text", "text": multimodal_input["text"]})
84
  messages=[{"role":"system", "content":[{"type":"text", "text":"Your name is Chatchat.And, your made by SungYoon.In Korean, 정성윤.And these are the instructions:"+"You are a helpful assietant."}]}]
85
  messages.append([{"role": "user", "content": content}])
86
  response = ""
@@ -88,7 +104,11 @@ def respond0(multimodal_input,password):
88
  model_id = "HuggingFaceM4/idefics2-8b"
89
 
90
  processor = AutoProcessor.from_pretrained(model_id)
91
- model = AutoModelForVision2Seq.from_pretrained("HuggingFaceM4/idefics2-8b",torch_dtype=torch.float16,quantization_config=quantization_config).to("cpu")
 
 
 
 
92
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
93
  inputs = processor(text=prompt, images=[images], return_tensors="pt")
94
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
@@ -102,9 +122,11 @@ def respond0(multimodal_input,password):
102
  token = generated_text
103
  response+=token
104
  yield response
 
105
  else:
106
-
107
- content={"type": "text", "text": multimodal_input["text"]}
 
108
  messages=[{"role":"system", "content":[{"type":"text", "text":"Your name is Chatchat.And, your made by SungYoon.In Korean, 정성윤.And these are the instructions:"+"You are a helpful assietant."}]}]
109
  messages.append([{"role": "user", "content": content}])
110
  response = ""
@@ -112,11 +134,7 @@ def respond0(multimodal_input,password):
112
  model_id = "HuggingFaceM4/idefics2-8b"
113
 
114
  processor = AutoProcessor.from_pretrained(model_id)
115
- model = AutoModelForVision2Seq.from_pretrained(
116
- "HuggingFaceM4/idefics2-8b",
117
- torch_dtype=torch.float16,
118
- quantization_config=quantization_config
119
- ).to("cpu")
120
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
121
  inputs = processor(text=prompt, images=[images], return_tensors="pt")
122
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
@@ -130,7 +148,7 @@ def respond0(multimodal_input,password):
130
  token = generated_text
131
  response+=token
132
  yield response
133
-
134
 
135
 
136
  def respond5(
@@ -556,6 +574,22 @@ ac=gr.ChatInterface(
556
  ),
557
  ],
558
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
559
  ab= gr.ChatInterface(
560
  respond3,
561
  chatbot=chatbot,
@@ -594,5 +628,5 @@ if __name__ == "__main__":
594
 
595
  if __name__ == "__main__":
596
  with gr.Blocks(theme="gstaff/xkcd") as ai:
597
- gr.TabbedInterface([aa, ac, ab, ae, aaaa,demo2, a7,a8], ["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", "gpt4(test)"])
598
  ai.launch(share=True)
 
1
  import gradio as gr
2
  import numpy as np
3
+ from Ai import chatbot, chatbot2, chatbot3, chatbot4, chatbot5, chatbot7
4
  from huggingface_hub import InferenceClient
5
  def chat(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p, top_k):
6
  m=AutoModel.from_pretrained("peterpeter8585/AI1")
 
24
  from diffusers import DiffusionPipeline
25
  import torch
26
  import transformers
27
+ from transformers import AutoModel as Mo, AutoTokenizer as To
28
+ model11=torch.load("zephyr.pt")
29
+ tokenizer11=torch.load("zephyr_tokenizer.pt")
30
  from transformers import BitsAndBytesConfig
31
 
32
  quantization_config = BitsAndBytesConfig(
 
37
  )
38
 
39
 
40
+ def res(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p):
41
+ messages = [{"role": "system", "content": "Your name is Chatchat.And, your made by SungYoon.In Korean, 정성윤.And these are the instructions.Whatever happens, you must follow it.:"+system_message}]
42
 
43
+ for val in history:
44
+ if val[0]:
45
+ messages.append({"role": "user", "content": val[0]})
46
+ if val[1]:
47
+ messages.append({"role": "assistant", "content": val[1]})
48
+
49
+ messages.append({"role": "user", "content": message})
50
+
51
+ response = ""
52
+
53
+ answer=model11(messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p)
54
+ token=answer
55
+ response += token
56
+ yield response
57
  from transformers import AutoModelForVision2Seq, AutoProcessor
58
  transformers.utils.move_cache()
59
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
95
  yield response
96
  def respond0(multimodal_input,password):
97
  if password==password1:
98
+ if multimodal_input["files"] == None:
99
+ content={"type": "text", "text": multimodal_input["text"]}
 
 
100
  messages=[{"role":"system", "content":[{"type":"text", "text":"Your name is Chatchat.And, your made by SungYoon.In Korean, 정성윤.And these are the instructions:"+"You are a helpful assietant."}]}]
101
  messages.append([{"role": "user", "content": content}])
102
  response = ""
 
104
  model_id = "HuggingFaceM4/idefics2-8b"
105
 
106
  processor = AutoProcessor.from_pretrained(model_id)
107
+ model = AutoModelForVision2Seq.from_pretrained(
108
+ "HuggingFaceM4/idefics2-8b",
109
+ torch_dtype=torch.float16,
110
+ quantization_config=quantization_config
111
+ ).to("cpu")
112
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
113
  inputs = processor(text=prompt, images=[images], return_tensors="pt")
114
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
 
122
  token = generated_text
123
  response+=token
124
  yield response
125
+
126
  else:
127
+ images = multimodal_input["files"]
128
+ content = [{"type": "image"} for _ in images]
129
+ content.append({"type": "text", "text": multimodal_input["text"]})
130
  messages=[{"role":"system", "content":[{"type":"text", "text":"Your name is Chatchat.And, your made by SungYoon.In Korean, 정성윤.And these are the instructions:"+"You are a helpful assietant."}]}]
131
  messages.append([{"role": "user", "content": content}])
132
  response = ""
 
134
  model_id = "HuggingFaceM4/idefics2-8b"
135
 
136
  processor = AutoProcessor.from_pretrained(model_id)
137
+ model = AutoModelForVision2Seq.from_pretrained("HuggingFaceM4/idefics2-8b",torch_dtype=torch.float16,quantization_config=quantization_config).to("cpu")
 
 
 
 
138
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
139
  inputs = processor(text=prompt, images=[images], return_tensors="pt")
140
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
 
148
  token = generated_text
149
  response+=token
150
  yield response
151
+
152
 
153
 
154
  def respond5(
 
574
  ),
575
  ],
576
  )
577
+ a9=gr.ChatInterface(
578
+ respond3,
579
+ chatbot=chatbot7,
580
+ additional_inputs=[
581
+ gr.Textbox(value="you are a helpful assistant. ", label="System message"),
582
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
583
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.1, step=0.1, label="Temperature"),
584
+ gr.Slider(
585
+ minimum=0.1,
586
+ maximum=1.0,
587
+ value=0.1,
588
+ step=0.05,
589
+ label="Top-p (nucleus sampling)",
590
+ ),
591
+ ],
592
+ )
593
  ab= gr.ChatInterface(
594
  respond3,
595
  chatbot=chatbot,
 
628
 
629
  if __name__ == "__main__":
630
  with gr.Blocks(theme="gstaff/xkcd") as ai:
631
+ gr.TabbedInterface([aa, ac, ab, ae, aaaa,demo2, a7,a8, a9], ["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", "gpt4(test)", "ai test"])
632
  ai.launch(share=True)