Nils Durner commited on
Commit
877d346
·
1 Parent(s): 910dbfd

image input support

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -5,7 +5,7 @@ import boto3
5
 
6
  from doc2json import process_docx
7
  from settings_mgr import generate_download_settings_js, generate_upload_settings_js
8
- from llm import LLM
9
 
10
  dump_controls = False
11
 
@@ -33,6 +33,16 @@ def add_file(history, file):
33
 
34
  return history
35
 
 
 
 
 
 
 
 
 
 
 
36
  def submit_text(txt_value):
37
  return add_text([chatbot, txt_value], [chatbot, txt_value])
38
 
@@ -177,6 +187,7 @@ with gr.Blocks() as demo:
177
 
178
  with gr.Row():
179
  btn = gr.UploadButton("📁 Upload", size="sm")
 
180
  undo_btn = gr.Button("↩️ Undo")
181
  undo_btn.click(undo, inputs=[chatbot], outputs=[chatbot])
182
 
@@ -244,5 +255,6 @@ with gr.Blocks() as demo:
244
  )
245
  txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
246
  file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False, postprocess=False)
 
247
 
248
  demo.queue().launch()
 
5
 
6
  from doc2json import process_docx
7
  from settings_mgr import generate_download_settings_js, generate_upload_settings_js
8
+ from llm import LLM, log_to_console, image_embed_prefix
9
 
10
  dump_controls = False
11
 
 
33
 
34
  return history
35
 
36
+ def add_img(history, files):
37
+ for file in files:
38
+ if log_to_console:
39
+ print(f"add_img {file.name}")
40
+ history = history + [(image_embed_prefix + file.name, None)]
41
+
42
+ gr.Info(f"Image added as {file.name}")
43
+
44
+ return history
45
+
46
  def submit_text(txt_value):
47
  return add_text([chatbot, txt_value], [chatbot, txt_value])
48
 
 
187
 
188
  with gr.Row():
189
  btn = gr.UploadButton("📁 Upload", size="sm")
190
+ img_btn = gr.UploadButton("🖼️ Upload", size="sm", file_count="multiple", file_types=["image"])
191
  undo_btn = gr.Button("↩️ Undo")
192
  undo_btn.click(undo, inputs=[chatbot], outputs=[chatbot])
193
 
 
255
  )
256
  txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
257
  file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False, postprocess=False)
258
+ img_msg = img_btn.upload(add_img, [chatbot, img_btn], [chatbot], queue=False, postprocess=False)
259
 
260
  demo.queue().launch()