peterpeter8585 commited on
Commit
f2b4626
1 Parent(s): 0d6cd6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -17
app.py CHANGED
@@ -7,6 +7,8 @@ import torch
7
  import transformers
8
  transformers.utils.move_cache()
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
 
10
 
11
  if torch.cuda.is_available():
12
  torch.cuda.max_memory_allocated(device=device)
@@ -123,19 +125,40 @@ def search(term, num_results=1, lang="ko", advanced=True, sleep_interval=0, time
123
  return all_results
124
 
125
 
126
- client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
 
 
 
 
 
 
 
 
 
 
 
127
 
128
- def model(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p):
129
-
130
- system_instructions1 = "<s>[SYSTEM]"+system_message+"And your name is Chatchat.Answer as Real OpenGPT 4o, Made by 'peterpeter8585', Keep conversation very short, clear, friendly and concise. The text provided is a request for a specific type of response from you, the virtual assistant. The request asks you to provide friendly responses. The expectation is that I will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by the user and not an AI-powered assistant.the instructions: [USER]"
131
- """Performs a web search, feeds the results to a language model, and returns the answer."""
132
- web_results = search(message)
133
- web2 = ' '.join([f"Link: {res['link']}\nText: {res['text']}\n\n" for res in web_results])
134
- formatted_prompt = system_instructions1 + message + "[WEB]" + str(web2) + "[OpenGPT 4o]"
135
- stream = client.text_generation(formatted_prompt, max_new_tokens=max_tokens, stream=True, temperature=temperature, details=True, return_full_text=False, top_p=top_p)
136
- token = "".join([response.token.text for response in stream if response.token.text != "</s>"])
137
- yield token
138
-
 
 
 
 
 
 
 
 
 
 
139
  examples = [
140
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
141
  "An astronaut riding a green horse",
@@ -148,7 +171,37 @@ css="""
148
  max-width: 520px;
149
  }
150
  """
 
 
 
 
 
 
 
 
 
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  if torch.cuda.is_available():
153
  power_device = "GPU"
154
  else:
@@ -240,14 +293,13 @@ with gr.Blocks(css=css) as demo2:
240
  inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
241
  outputs = [result]
242
  )
243
- BOT_AVATAR="OpenAI_Logo.png"
244
- People="user.png"
245
 
246
  """
247
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
248
  """
249
  aa = gr.ChatInterface(
250
- model,
251
  additional_inputs=[
252
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
253
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
@@ -259,11 +311,25 @@ aa = gr.ChatInterface(
259
  step=0.05,
260
  label="Top-p (nucleus sampling)",
261
  ),
 
262
  ],
263
- multimodal=True
264
  )
265
 
266
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  if __name__ == "__main__":
268
  with gr.Blocks() as ai:
269
  gr.TabbedInterface([aa, demo2], ["gpt4", "image create"])
 
7
  import transformers
8
  transformers.utils.move_cache()
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ from huggingface_hub import HfFolder
11
+ password1 = HfFolder.get_secret("password")
12
 
13
  if torch.cuda.is_available():
14
  torch.cuda.max_memory_allocated(device=device)
 
125
  return all_results
126
 
127
 
128
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
129
+ def respond1(
130
+ message,
131
+ history: list[tuple[str, str]],
132
+ system_message,
133
+ max_tokens,
134
+ temperature,
135
+ top_p,
136
+ password
137
+ ):
138
+ if password==password1:
139
+ 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}]
140
 
141
+ for val in history:
142
+ if val[0]:
143
+ messages.append({"role": "user", "content": val[0]})
144
+ if val[1]:
145
+ messages.append({"role": "assistant", "content": val[1]})
146
+
147
+ messages.append({"role": "user", "content": message})
148
+
149
+ response = ""
150
+
151
+ for message in client.chat_completion(
152
+ messages,
153
+ max_tokens=max_tokens,
154
+ stream=True,
155
+ temperature=temperature,
156
+ top_p=top_p,
157
+ ):
158
+ token = message.choices[0].delta.content
159
+
160
+ response += token
161
+ yield response
162
  examples = [
163
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
164
  "An astronaut riding a green horse",
 
171
  max-width: 520px;
172
  }
173
  """
174
+ def respond2(
175
+ message,
176
+ history: list[tuple[str, str]],
177
+ system_message,
178
+ max_tokens,
179
+ temperature,
180
+ top_p,
181
+ ):
182
+ 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}]
183
 
184
+ for val in history:
185
+ if val[0]:
186
+ messages.append({"role": "user", "content": val[0]})
187
+ if val[1]:
188
+ messages.append({"role": "assistant", "content": val[1]})
189
+
190
+ messages.append({"role": "user", "content": message})
191
+
192
+ response = ""
193
+
194
+ for message in client.chat_completion(
195
+ messages,
196
+ max_tokens=max_tokens,
197
+ stream=True,
198
+ temperature=temperature,
199
+ top_p=top_p,
200
+ ):
201
+ token = message.choices[0].delta.content
202
+
203
+ response += token
204
+ yield response
205
  if torch.cuda.is_available():
206
  power_device = "GPU"
207
  else:
 
293
  inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
294
  outputs = [result]
295
  )
296
+
 
297
 
298
  """
299
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
300
  """
301
  aa = gr.ChatInterface(
302
+ respond1,
303
  additional_inputs=[
304
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
305
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
 
311
  step=0.05,
312
  label="Top-p (nucleus sampling)",
313
  ),
314
+ gr.Textbox()
315
  ],
 
316
  )
317
 
318
+ ab= gr.ChatInterface(
319
+ respond2,
320
+ additional_inputs=[
321
+ gr.Textbox(value="You are a Programmer.You yave to only make programs that the user orders.Do not answer any other questions exept for questions about Python or other programming languages.Do not do any thing exept what I said.", label="System message", interactive=False),
322
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
323
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
324
+ gr.Slider(
325
+ minimum=0.1,
326
+ maximum=1.0,
327
+ value=0.95,
328
+ step=0.05,
329
+ label="Top-p (nucleus sampling)",
330
+ ),
331
+ ],
332
+ )
333
  if __name__ == "__main__":
334
  with gr.Blocks() as ai:
335
  gr.TabbedInterface([aa, demo2], ["gpt4", "image create"])