samnji commited on
Commit
fcec08f
ยท
1 Parent(s): 5d8493d
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -38,24 +38,24 @@ def encode_image(image):
38
  inputs = processor(images=[image], return_tensors="pt", padding=True, truncation=True)
39
  return inputs
40
 
41
- def bot(history, message, image=None):
42
- if image is not None:
43
- image = preprocess_image(image)
44
- top_3_products = initial_query(image, message)
 
 
45
  output_html = generate_output_html(top_3_products)
46
- history = history + [(message, output_html)]
47
- return history
48
-
49
- def send_message(chatbot, txt):
50
- bot(chatbot, txt)
51
 
52
  chatbot = gr.Chatbot([]).style(height=750)
53
  txt = gr.Textbox(placeholder="Enter text and press enter, or upload an image", show_label=False)
54
- btn = gr.UploadButton("๐Ÿ“", file_types=["image", "video", "audio"])
55
- send_btn = gr.Button("Send", on_click=send_message, args=[chatbot, txt])
56
 
57
  with gr.Blocks() as demo:
58
  chatbot
59
  gr.Row(txt, btn, send_btn)
60
 
61
  demo.launch()
 
 
38
  inputs = processor(images=[image], return_tensors="pt", padding=True, truncation=True)
39
  return inputs
40
 
41
+ def send_message(chatbot, txt, btn):
42
+ if btn is not None:
43
+ image = preprocess_image(btn)
44
+ else:
45
+ image = None
46
+ top_3_products = initial_query(image, txt)
47
  output_html = generate_output_html(top_3_products)
48
+ chatbot.append_message("You", txt)
49
+ chatbot.append_message("AI", output_html)
 
 
 
50
 
51
  chatbot = gr.Chatbot([]).style(height=750)
52
  txt = gr.Textbox(placeholder="Enter text and press enter, or upload an image", show_label=False)
53
+ btn = gr.UploadButton("๐Ÿ“ธ", file_types=["image", "video", "audio"])
54
+ send_btn = gr.Button("Send", action=send_message)
55
 
56
  with gr.Blocks() as demo:
57
  chatbot
58
  gr.Row(txt, btn, send_btn)
59
 
60
  demo.launch()
61
+