ryanzhangfan commited on
Commit
6a25365
โ€ข
1 Parent(s): 0bd8053

add examples and license

Browse files
app.py CHANGED
@@ -6,7 +6,7 @@
6
  # Email : zhangfan@baai.ac.cn
7
  # Institute : Beijing Academy of Artificial Intelligence (BAAI)
8
  # Create On : 2023-12-11 15:34
9
- # Last Modified : 2023-12-20 14:22
10
  # File Name : app.py
11
  # Description :
12
  #
@@ -66,14 +66,6 @@ if __name__ == "__main__":
66
  theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue"),
67
  )
68
 
69
- # demo_all.queue(
70
- # max_size=20,
71
- # status_update_rate=3,
72
- # api_open=False,
73
- # default_concurrency_limit=args.concurrency_count,
74
- # ).launch(
75
- # share=args.share,
76
- # )
77
  demo_all.queue(
78
  concurrency_count=args.concurrency_count,
79
  status_update_rate=3,
 
6
  # Email : zhangfan@baai.ac.cn
7
  # Institute : Beijing Academy of Artificial Intelligence (BAAI)
8
  # Create On : 2023-12-11 15:34
9
+ # Last Modified : 2023-12-20 15:09
10
  # File Name : app.py
11
  # Description :
12
  #
 
66
  theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue"),
67
  )
68
 
 
 
 
 
 
 
 
 
69
  demo_all.queue(
70
  concurrency_count=args.concurrency_count,
71
  status_update_rate=3,
demo/chat_frontend.py CHANGED
@@ -6,7 +6,7 @@
6
  # Email : zhangfan@baai.ac.cn
7
  # Institute : Beijing Academy of Artificial Intelligence (BAAI)
8
  # Create On : 2023-12-12 18:05
9
- # Last Modified : 2023-12-20 14:25
10
  # File Name : chat_frontend.py
11
  # Description :
12
  #
@@ -23,6 +23,7 @@ import gradio as gr
23
  from .meta import ConvMeta, Role, DataMeta
24
  from .utils import extract_frames
25
  from .utils import frontend_logger as logging
 
26
 
27
  CONTROLLER_URL = ""
28
 
@@ -138,6 +139,19 @@ def generate(
138
  return meta.format_chatbot(), meta
139
 
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  def build_chat(args):
142
  global CONTROLLER_URL
143
  CONTROLLER_URL = args.controller_url
@@ -145,6 +159,7 @@ def build_chat(args):
145
  with gr.Blocks(title="Emu", theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue")) as demo:
146
  state = gr.State()
147
 
 
148
  with gr.Row():
149
  with gr.Column(scale=2):
150
  with gr.Row():
@@ -191,6 +206,18 @@ def build_chat(args):
191
  clear_btn = gr.Button(value="๐Ÿ—‘๏ธ Clear History")
192
  generate_btn = gr.Button(value="Generate")
193
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  clear_btn.click(clear_history, inputs=state, outputs=[chatbot, state])
196
  textbox.submit(
@@ -245,5 +272,16 @@ def build_chat(args):
245
  state,
246
  ],
247
  )
 
 
 
 
 
 
 
 
 
 
 
248
 
249
  return demo
 
6
  # Email : zhangfan@baai.ac.cn
7
  # Institute : Beijing Academy of Artificial Intelligence (BAAI)
8
  # Create On : 2023-12-12 18:05
9
+ # Last Modified : 2023-12-20 15:59
10
  # File Name : chat_frontend.py
11
  # Description :
12
  #
 
23
  from .meta import ConvMeta, Role, DataMeta
24
  from .utils import extract_frames
25
  from .utils import frontend_logger as logging
26
+ from .constants import LICENSE, TERM_OF_USE
27
 
28
  CONTROLLER_URL = ""
29
 
 
139
  return meta.format_chatbot(), meta
140
 
141
 
142
+ def push_examples(examples, meta):
143
+ if meta is None:
144
+ meta = ConvMeta()
145
+
146
+ meta.clear()
147
+
148
+ image, prompt = examples
149
+ meta.append(Role.USER, DataMeta.build(image=Image.open(image)))
150
+ meta.append(Role.USER, DataMeta.build(text=prompt))
151
+
152
+ return meta.format_chatbot(), meta
153
+
154
+
155
  def build_chat(args):
156
  global CONTROLLER_URL
157
  CONTROLLER_URL = args.controller_url
 
159
  with gr.Blocks(title="Emu", theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue")) as demo:
160
  state = gr.State()
161
 
162
+
163
  with gr.Row():
164
  with gr.Column(scale=2):
165
  with gr.Row():
 
206
  clear_btn = gr.Button(value="๐Ÿ—‘๏ธ Clear History")
207
  generate_btn = gr.Button(value="Generate")
208
 
209
+ with gr.Row():
210
+ examples = gr.Dataset(components=[gr.Image(type="pil", visible=False), gr.Textbox(visible=False)],
211
+ label="Examples",
212
+ samples=[
213
+ ["./examples/roadmap.jpg", "Imagine you are a guiding robot.\nHere is a photo I took. Please tell me how to get to the restroom."],
214
+ ["./examples/shapes.jpeg", "Look at this sequence of three shapes. What shape should come as the fourth shape? Explain your reasoning with detailed descriptions of the first shapes."],
215
+ ],
216
+ )
217
+
218
+ gr.Markdown(TERM_OF_USE)
219
+ gr.Markdown(LICENSE)
220
+
221
 
222
  clear_btn.click(clear_history, inputs=state, outputs=[chatbot, state])
223
  textbox.submit(
 
272
  state,
273
  ],
274
  )
275
+ examples.click(
276
+ push_examples,
277
+ inputs=[
278
+ examples,
279
+ state,
280
+ ],
281
+ outputs=[
282
+ chatbot,
283
+ state,
284
+ ]
285
+ )
286
 
287
  return demo
demo/constants.py CHANGED
@@ -45,3 +45,8 @@ VIDEO = 32004
45
  DEFAULT_IMG_PLACEHOLDER = "[<IMG_PLH>]"
46
  DEFAULT_VID_PLACEHOLDER = "[<VID_PLH>]"
47
  FAKE_VIDEO_END_TOKEN = "[/VIDEO]"
 
 
 
 
 
 
45
  DEFAULT_IMG_PLACEHOLDER = "[<IMG_PLH>]"
46
  DEFAULT_VID_PLACEHOLDER = "[<VID_PLH>]"
47
  FAKE_VIDEO_END_TOKEN = "[/VIDEO]"
48
+
49
+ # LICENSE & TERM OF USE
50
+ TERM_OF_USE = "### Terms of use\n๐Ÿ“ŒBy using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. The service may collect user dialogue data for future research."
51
+
52
+ LICENSE = "### License\n๐Ÿ“ŒThe service is a research preview intended for non-commercial use only, subject to the model [License](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md) of LLaMA, [Terms of Use](https://openai.com/policies/terms-of-use) of content by OpenAI, and [Privacy Practices](https://chromewebstore.google.com/detail/sharegpt-share-your-chatg/daiacboceoaocpibfodeljbdfacokfjb) of ShareGPT. Please contact us if you find any potential violation."
demo/generation_frontend.py CHANGED
@@ -6,7 +6,7 @@
6
  # Email : zhangfan@baai.ac.cn
7
  # Institute : Beijing Academy of Artificial Intelligence (BAAI)
8
  # Create On : 2023-12-11 15:35
9
- # Last Modified : 2023-12-20 14:15
10
  # File Name : generation_frontend.py
11
  # Description :
12
  #
@@ -24,6 +24,7 @@ import gradio as gr
24
  from .constants import EVA_IMAGE_SIZE
25
  from .meta import ConvMeta, Role, DataMeta
26
  from .utils import frontend_logger as logging
 
27
 
28
  CONTROLLER_URL = ""
29
 
@@ -127,6 +128,22 @@ def generate(meta, classifier_free_guidance, steps):
127
 
128
  return meta.format_chatbot(), meta
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  def build_generation(args):
132
  global CONTROLLER_URL
@@ -180,6 +197,26 @@ def build_generation(args):
180
  clear_btn = gr.Button(value="๐Ÿ—‘๏ธ Clear History")
181
  generate_btn = gr.Button(value="Generate")
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  clear_btn.click(clear_history, inputs=state, outputs=[chatbot, state])
184
 
185
  textbox.submit(
@@ -245,4 +282,28 @@ def build_generation(args):
245
  ]
246
  )
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  return demo
 
6
  # Email : zhangfan@baai.ac.cn
7
  # Institute : Beijing Academy of Artificial Intelligence (BAAI)
8
  # Create On : 2023-12-11 15:35
9
+ # Last Modified : 2023-12-20 16:18
10
  # File Name : generation_frontend.py
11
  # Description :
12
  #
 
24
  from .constants import EVA_IMAGE_SIZE
25
  from .meta import ConvMeta, Role, DataMeta
26
  from .utils import frontend_logger as logging
27
+ from .constants import LICENSE, TERM_OF_USE
28
 
29
  CONTROLLER_URL = ""
30
 
 
128
 
129
  return meta.format_chatbot(), meta
130
 
131
+ def push_examples(examples, meta):
132
+ if meta is None:
133
+ meta = ConvMeta()
134
+
135
+ meta.clear()
136
+
137
+ if len(examples) == 1:
138
+ prompt, = examples
139
+ meta.append(Role.USER, DataMeta.build(text=prompt))
140
+ elif len(examples) == 2:
141
+ image, prompt = examples
142
+ meta.append(Role.USER, DataMeta.build(image=Image.open(image)))
143
+ meta.append(Role.USER, DataMeta.build(text=prompt))
144
+
145
+ return meta.format_chatbot(), meta
146
+
147
 
148
  def build_generation(args):
149
  global CONTROLLER_URL
 
197
  clear_btn = gr.Button(value="๐Ÿ—‘๏ธ Clear History")
198
  generate_btn = gr.Button(value="Generate")
199
 
200
+ with gr.Row():
201
+ examples_t2i = gr.Dataset(components=[gr.Textbox(visible=False)],
202
+ label="Examples",
203
+ samples=[
204
+ ["impressionist painting of an astronaut in a jungle"],
205
+ ["A poised woman with short, curly hair and a warm smile, dressed in elegant attire, standing in front of a historic stone bridge in a serene park at sunset."],
206
+ ],
207
+ )
208
+ with gr.Row():
209
+ examples_it2i = gr.Dataset(components=[gr.Image(type="pil", visible=False), gr.Textbox(visible=False)],
210
+ samples=[
211
+ ["./examples/dog2.jpg", "wearing a red hat on the beach."],
212
+ ["./examples/doodle.png", "Replace the text background color with yellow"],
213
+ ],
214
+ )
215
+
216
+
217
+ gr.Markdown(TERM_OF_USE)
218
+ gr.Markdown(LICENSE)
219
+
220
  clear_btn.click(clear_history, inputs=state, outputs=[chatbot, state])
221
 
222
  textbox.submit(
 
282
  ]
283
  )
284
 
285
+ examples_t2i.click(
286
+ push_examples,
287
+ inputs=[
288
+ examples_t2i,
289
+ state,
290
+ ],
291
+ outputs=[
292
+ chatbot,
293
+ state,
294
+ ]
295
+ )
296
+ examples_it2i.click(
297
+ push_examples,
298
+ inputs=[
299
+ examples_it2i,
300
+ state,
301
+ ],
302
+ outputs=[
303
+ chatbot,
304
+ state,
305
+ ]
306
+ )
307
+
308
+
309
  return demo