alvanlii commited on
Commit
3b033c6
1 Parent(s): 6ee4b37

Fixed state and image upload

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -19,13 +19,14 @@ MODEL_DIR = './fromage_model/fromage_vis4'
19
 
20
  class ChatBotCheese:
21
  def __init__(self):
22
- from huggingface_hub import hf_hub_download
23
- model_ckpt_path = hf_hub_download("alvanlii/fromage", "pretrained_ckpt.pth.tar")
24
- self.model = models.load_fromage(MODEL_DIR, model_ckpt_path)
 
25
  self.curr_image = None
26
 
27
  def add_image(self, state, image_in):
28
- state = state + [(f"![](/file={image_in.name})", "Ok, now type your message")]
29
  self.curr_image = Image.open(image_in.name).convert('RGB')
30
  return state, state
31
 
@@ -36,9 +37,9 @@ class ChatBotCheese:
36
 
37
  def chat(self, input_text, state, ret_scale_factor, num_ims, num_words, temp, chat_state):
38
  chat_state.append(f'Q: {input_text} \nA:')
39
- chat_history = " ".join(chat_state)
40
  model_input = []
41
- print(chat_history)
42
  if self.curr_image is not None:
43
  model_input = [self.curr_image, chat_history]
44
  else:
@@ -55,7 +56,7 @@ class ChatBotCheese:
55
  for im_name in im_names:
56
  response += f'<img src="/file={im_name}">'
57
  state.append((input_text, response.replace("[RET]", "")))
58
- # self.curr_image = None
59
  return state, state, chat_state
60
 
61
  def reset(self):
@@ -111,10 +112,7 @@ class ChatBotCheese:
111
  txt.submit(lambda :"", None, txt)
112
  btn.upload(self.add_image, [gr_state, btn], [gr_state, chatbot])
113
  reset_btn.click(self.reset, [], [gr_state, chatbot, gr_chat_state])
114
-
115
- # chatbot.change(fn = upload_button_config, outputs=btn_upload)
116
- # text_in.submit(None, [], [], _js = "() => document.getElementById('#chatbot-component').scrollTop = document.getElementById('#chatbot-component').scrollHeight")
117
-
118
  demo.launch(share=False, server_name="0.0.0.0")
119
 
120
  def main():
 
19
 
20
  class ChatBotCheese:
21
  def __init__(self):
22
+ # from huggingface_hub import hf_hub_download
23
+ # model_ckpt_path = hf_hub_download("alvanlii/fromage", "pretrained_ckpt.pth.tar")
24
+ # self.model = models.load_fromage(MODEL_DIR, model_ckpt_path)
25
+ self.model = models.load_fromage(MODEL_DIR)
26
  self.curr_image = None
27
 
28
  def add_image(self, state, image_in):
29
+ state = state + [(f'<img src="/file={image_in.name}">', "Ok, now type your message")]
30
  self.curr_image = Image.open(image_in.name).convert('RGB')
31
  return state, state
32
 
 
37
 
38
  def chat(self, input_text, state, ret_scale_factor, num_ims, num_words, temp, chat_state):
39
  chat_state.append(f'Q: {input_text} \nA:')
40
+ chat_history = "".join(chat_state)
41
  model_input = []
42
+ # print(chat_history)
43
  if self.curr_image is not None:
44
  model_input = [self.curr_image, chat_history]
45
  else:
 
56
  for im_name in im_names:
57
  response += f'<img src="/file={im_name}">'
58
  state.append((input_text, response.replace("[RET]", "")))
59
+ self.curr_image = None
60
  return state, state, chat_state
61
 
62
  def reset(self):
 
112
  txt.submit(lambda :"", None, txt)
113
  btn.upload(self.add_image, [gr_state, btn], [gr_state, chatbot])
114
  reset_btn.click(self.reset, [], [gr_state, chatbot, gr_chat_state])
115
+
 
 
 
116
  demo.launch(share=False, server_name="0.0.0.0")
117
 
118
  def main():