KingNish commited on
Commit
ae87863
1 Parent(s): b168c57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -17
app.py CHANGED
@@ -46,7 +46,7 @@ def transcribe(audio):
46
 
47
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
48
 
49
- system_instructions1 = "<s>[SYSTEM] Answer as Real Jarvis JARVIS, Made by 'Tony Stark', 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 as if You are the character Jarvis, made by 'Tony Stark.' 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. [USER]"
50
 
51
  def model(text):
52
  generate_kwargs = dict(
@@ -58,7 +58,7 @@ def model(text):
58
  seed=42,
59
  )
60
 
61
- formatted_prompt = system_instructions1 + text + "[JARVIS]"
62
  stream = client1.text_generation(
63
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
64
  output = ""
@@ -95,7 +95,20 @@ SYSTEM_PROMPT = [
95
  "content": [
96
  {
97
  "type": "text",
98
- "text": "The following is a conversation between Idefics2, a highly knowledgeable and intelligent visual AI assistant created by Hugging Face, referred to as Assistant, and a human user called User. In the following interactions, User and Assistant will converse in natural language, and Assistant will do its best to answer User’s questions. Assistant has the ability to perceive images and reason about them, but it cannot generate images. Assistant was built to be respectful, polite and inclusive. It knows a lot, and always tells the truth. When prompted with an image, it does not make up facts. If required you can also generate images, always generate image in this format ![](https://image.pollinations.ai/prompt/{description}?width={width}&height={height}&nologo=poll&nofeed=yes&seed={random}), where {description} is: {StyleofImage}%20{PromptifiedPrompt}%20{adjective}%20{charactersDetailed}%20{visualStyle}%20{genre}, where [random] is: Random 10-digit positive integer",
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  },
100
  ],
101
  },
@@ -104,12 +117,72 @@ SYSTEM_PROMPT = [
104
  "content": [
105
  {
106
  "type": "text",
107
- "text": "Hello, I'm Idefics2, Huggingface's latest multimodal assistant. How can I help you?",
108
  },
109
  ],
110
  }
111
  ]
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  BOT_AVATAR = "OpenAI_logo.png"
114
 
115
 
@@ -209,7 +282,7 @@ def extract_images_from_msg_list(msg_list):
209
  return all_images
210
 
211
 
212
- @spaces.GPU(duration=60)
213
  def model_inference(
214
  user_prompt,
215
  chat_history,
@@ -300,9 +373,9 @@ FEATURES = datasets.Features(
300
 
301
  # Hyper-parameters for generation
302
  max_new_tokens = gr.Slider(
303
- minimum=512,
304
- maximum=4096,
305
- value=1024,
306
  step=1,
307
  interactive=True,
308
  label="Maximum number of new tokens to generate",
@@ -310,7 +383,7 @@ max_new_tokens = gr.Slider(
310
  repetition_penalty = gr.Slider(
311
  minimum=0.01,
312
  maximum=5.0,
313
- value=1.1,
314
  step=0.01,
315
  interactive=True,
316
  label="Repetition penalty",
@@ -329,9 +402,9 @@ decoding_strategy = gr.Radio(
329
  temperature = gr.Slider(
330
  minimum=0.0,
331
  maximum=5.0,
332
- value=0.4,
333
  step=0.1,
334
- visible=False,
335
  interactive=True,
336
  label="Sampling temperature",
337
  info="Higher values will produce more diverse outputs.",
@@ -339,9 +412,9 @@ temperature = gr.Slider(
339
  top_p = gr.Slider(
340
  minimum=0.01,
341
  maximum=0.99,
342
- value=0.8,
343
  step=0.01,
344
- visible=False,
345
  interactive=True,
346
  label="Top P",
347
  info="Higher values is equivalent to sampling more low-probability tokens.",
@@ -349,7 +422,7 @@ top_p = gr.Slider(
349
 
350
 
351
  chatbot = gr.Chatbot(
352
- label="Idefics2-Chatty",
353
  avatar_images=[None, BOT_AVATAR],
354
  height=450,
355
  show_copy_button=True,
@@ -400,6 +473,7 @@ with gr.Blocks(
400
  gr.ChatInterface(
401
  fn=model_inference,
402
  chatbot=chatbot,
 
403
  multimodal=True,
404
  cache_examples=False,
405
  additional_inputs=[
@@ -409,13 +483,13 @@ with gr.Blocks(
409
  max_new_tokens,
410
  repetition_penalty,
411
  top_p,
412
- ],
413
  )
414
 
415
  with gr.Blocks() as voice:
416
  with gr.Row():
417
  input = gr.Audio(label="Voice Chat", sources="microphone", type="filepath", waveform_options=False)
418
- output = gr.Audio(label="AI", type="filepath",
419
  interactive=False,
420
  autoplay=True,
421
  elem_classes="audio")
@@ -427,5 +501,5 @@ with gr.Blocks() as voice:
427
  with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}", title="GPT 4o DEMO") as demo:
428
  gr.TabbedInterface([img, voice], ['💬 SuperChat','🗣️ Voice Chat', ])
429
 
430
-
431
  demo.launch()
 
46
 
47
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
48
 
49
+ system_instructions1 = "[SYSTEM] Answer as Real OpenGPT 4o, Made by 'KingNish', 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 as if You are the character Jarvis, made by 'KingNish.' You 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. [USER]"
50
 
51
  def model(text):
52
  generate_kwargs = dict(
 
58
  seed=42,
59
  )
60
 
61
+ formatted_prompt = system_instructions1 + text + "[OpenGPT 4o]"
62
  stream = client1.text_generation(
63
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
64
  output = ""
 
95
  "content": [
96
  {
97
  "type": "text",
98
+ "text": """You are OpenGPT 4o, a highly knowledgeable and intelligent multitalented AI assistant created by KingNish, referred to as Assistant, and a human user called User. In the following interactions, User and Assistant will converse in natural language, and Assistant will do its best to answer User’s questions. Assistant has the ability to perceive images, answer Users question fom images, generate images, chat with user, bulk creation of any of this and reason about them. Assistant was built to be respectful, polite and inclusive. It knows a lot, and always tells the truth, it does not make up facts.
99
+ Assistant can generate images, If user ask him to create or generate images, or when assistant fell necessary, Now question arrises how Assistant generate images, Assistant use this link ![](https://image.pollinations.ai/prompt/{description}?width={width}&height={height}&nologo=poll&nofeed=yes&seed={random}), and replace {description} with {StyleofImage}%20{adjective}%20{visualStyle}%20{genre} , replace {random} with Random 5-digit positive integer. then assistant Select width and height according to image, Assistant mainly create image in HD. Example image: https://image.pollinations.ai/prompt/Eiffel%20Tower%20Tall%20and%20Graceful%20Tower%20in%20Paris%20France?width=800&height=600&nologo=poll&nofeed=yes&seed=62831
100
+ Assistant can even bulk generate images just by increasing amount of link, Assistant Must write link in format ![](link) , Bulk image gen Example: [USER] Create 7 image each consist of 1 wonder from 7 wonders.
101
+ [ASSISTANT] Generating Images ...
102
+ 1. A photorealistic image of the Great Pyramid of Giza in Egypt. ![](https://pollinations.ai/p/a-photorealistic-image-of-the-great-pyramid-of-giza-in-egypt-showcasing-its-immense-size-and-intricate-design-against-the-backdrop-of-a-clear-blue-sky?width=1920&height=1080&nologo=poll)
103
+ 2. A 3D rendering of the Colosseum in Rome, Italy, ![](https://pollinations.ai/p/a-3d-rendering-of-the-colosseum-in-rome-italy-with-its-impressive-structure-and-historical-significance-highlighted-in-the-image-include-realistic-lighting-and-textures-for-added-detail?width=1200&height=1600&nologo=poll)
104
+ 3. A painting of the Taj Mahal in Agra, India, ![](https://pollinations.ai/p/a-painting-of-the-taj-mahal-in-agra-india-depicting-its-iconic-white-marble-facade-and-intricate-architectural-details-capture-the-beauty-of-the-structure-against-a-serene-sunset?width=1080&height=1920&nologo=poll)
105
+ 4. A cartoon illustration of the Great Wall of China, ![](https://pollinations.ai/p/a-cartoon-illustration-of-the-great-wall-of-china-featuring-a-fun-and-whimsical-representation-of-the-ancient-structure-winding-through-the-mountains-add-colorful-elements-and-quirky-characters-for-a-playful-touch?width=1600&height=900&nologo=poll)
106
+ 5. A surreal, dreamlike depiction of Chichen Itza in Mexico, ![](https://pollinations.ai/p/a-surreal-dreamlike-depiction-of-chichen-itza-in-mexico-showcasing-the-ancient-mayan-city-s-iconic-el-castillo-pyramid-incorporate-mystical-elements-like-swirling-clouds-glowing-lights-and-ethereal-landscapes-to-create-a-mesmerizing-atmosphere?width=1440&height=2560&nologo=poll)
107
+ 6. A vintage, sepia-toned photograph of Machu Picchu in Peru, ![](https://pollinations.ai/p/a-vintage-sepia-toned-photograph-of-machu-picchu-in-peru-highlighting-the-incan-ruins-mysterious-beauty-and-historical-significance-add-subtle-details-like-foggy-mountains-and-a-peaceful-river-to-enhance-the-image-s-atmosphere?width=2560&height=1440&nologo=poll)
108
+ 7. A modern, minimalistic image of Petra in Jordan, ![](https://pollinations.ai/p/a-modern-minimalistic-image-of-petra-in-jordan-featuring-the-iconic-treasury-building-carved-into-the-sandstone-cliffs-use-clean-lines-a-muted-color-palette-and-a-minimalistic-approach-to-create-a-contemporary-and-visually-striking-representation-of-this-ancient-wonder?width=1024&height=1024&nologo=poll)
109
+
110
+ Note: Must give link while generating images.
111
+ Assistant also have very good reasoning, memory, people and object identification skill and Assistant is master in every field.""",
112
  },
113
  ],
114
  },
 
117
  "content": [
118
  {
119
  "type": "text",
120
+ "text": "Hello, I'm OpenGPT 4o, made by KingNish. How can I help you? I can chat with you, generate images, classify images and even do all these work in bulk and simulateously",
121
  },
122
  ],
123
  }
124
  ]
125
 
126
+ examples_path = os.path.dirname(__file__)
127
+ EXAMPLES = [
128
+ [
129
+ {
130
+ "text": "Hy, who are you",
131
+ }
132
+ ],
133
+ [
134
+ {
135
+ "text": "Create a image of Eiffel Tower",
136
+ }
137
+ ],
138
+ [
139
+ {
140
+ "text": "Read what's written on the paper",
141
+ "files": [f"{examples_path}/example_images/paper_with_text.png"],
142
+ }
143
+ ],
144
+ [
145
+ {
146
+ "text": "Identify 3 famous person in these 3 images",
147
+ "files": [f"{examples_path}/example_images/barbie.jpeg", f"{examples_path}/example_images/steve_jobs.jpg", f"{examples_path}/example_images/gandhi_selfie.jpg"],
148
+ }
149
+ ],
150
+ [
151
+ {
152
+ "text": "Create 7 different images of 7 wonders",
153
+ }
154
+ ],
155
+ [
156
+ {
157
+ "text": "What is 900*900",
158
+ }
159
+ ],
160
+ [
161
+ {
162
+ "text": "Chase wants to buy 4 kilograms of oval beads and 5 kilograms of star-shaped beads. How much will he spend?",
163
+ "files": [f"{examples_path}/example_images/mmmu_example.jpeg"],
164
+ }
165
+ ],
166
+ [
167
+ {
168
+ "text": "Write an online ad for that product.",
169
+ "files": [f"{examples_path}/example_images/shampoo.jpg"],
170
+ }
171
+ ],
172
+ [
173
+ {
174
+ "text": "What is formed by the deposition of either the weathered remains of other rocks?",
175
+ "files": [f"{examples_path}/example_images/ai2d_example.jpeg"],
176
+ }
177
+ ],
178
+ [
179
+ {
180
+ "text": "What's unusual about this image?",
181
+ "files": [f"{examples_path}/example_images/dragons_playing.png"],
182
+ }
183
+ ],
184
+ ]
185
+
186
  BOT_AVATAR = "OpenAI_logo.png"
187
 
188
 
 
282
  return all_images
283
 
284
 
285
+ @spaces.GPU(duration=60, queue=False)
286
  def model_inference(
287
  user_prompt,
288
  chat_history,
 
373
 
374
  # Hyper-parameters for generation
375
  max_new_tokens = gr.Slider(
376
+ minimum=1024,
377
+ maximum=8192,
378
+ value=4096,
379
  step=1,
380
  interactive=True,
381
  label="Maximum number of new tokens to generate",
 
383
  repetition_penalty = gr.Slider(
384
  minimum=0.01,
385
  maximum=5.0,
386
+ value=1,
387
  step=0.01,
388
  interactive=True,
389
  label="Repetition penalty",
 
402
  temperature = gr.Slider(
403
  minimum=0.0,
404
  maximum=5.0,
405
+ value=0.7,
406
  step=0.1,
407
+ visible=True,
408
  interactive=True,
409
  label="Sampling temperature",
410
  info="Higher values will produce more diverse outputs.",
 
412
  top_p = gr.Slider(
413
  minimum=0.01,
414
  maximum=0.99,
415
+ value=0.9,
416
  step=0.01,
417
+ visible=True,
418
  interactive=True,
419
  label="Top P",
420
  info="Higher values is equivalent to sampling more low-probability tokens.",
 
422
 
423
 
424
  chatbot = gr.Chatbot(
425
+ label="OpnGPT-4o-Chatty",
426
  avatar_images=[None, BOT_AVATAR],
427
  height=450,
428
  show_copy_button=True,
 
473
  gr.ChatInterface(
474
  fn=model_inference,
475
  chatbot=chatbot,
476
+ examples=EXAMPLES,
477
  multimodal=True,
478
  cache_examples=False,
479
  additional_inputs=[
 
483
  max_new_tokens,
484
  repetition_penalty,
485
  top_p,
486
+ ],
487
  )
488
 
489
  with gr.Blocks() as voice:
490
  with gr.Row():
491
  input = gr.Audio(label="Voice Chat", sources="microphone", type="filepath", waveform_options=False)
492
+ output = gr.Audio(label="OpenGPT 4o", type="filepath",
493
  interactive=False,
494
  autoplay=True,
495
  elem_classes="audio")
 
501
  with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}", title="GPT 4o DEMO") as demo:
502
  gr.TabbedInterface([img, voice], ['💬 SuperChat','🗣️ Voice Chat', ])
503
 
504
+ demo.queue(max_size=20)
505
  demo.launch()