Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -42,31 +42,31 @@ def bot_streaming(message, history):
42
  if type(hist[0])==tuple:
43
  image = hist[0][0]
44
 
45
- if image is None:
46
- gr.Error("You need to upload an image for LLaVA to work.")
47
- prompt=f"<|start_header_id|>user<|end_header_id|>\n\n<image>\n{message['text']}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
48
- print(f"prompt: {prompt}")
49
- image = Image.open(image)
50
- inputs = processor(prompt, image, return_tensors='pt').to(0, torch.float16)
51
 
52
- streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True})
53
- generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
54
- generated_text = ""
55
 
56
- thread = Thread(target=model.generate, kwargs=generation_kwargs)
57
- thread.start()
58
 
59
- text_prompt =f"<|start_header_id|>user<|end_header_id|>\n\n{message['text']}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
60
- print(f"text_prompt: {text_prompt}")
61
 
62
- buffer = ""
63
- for new_text in streamer:
64
 
65
- buffer += new_text
66
 
67
- generated_text_without_prompt = buffer[len(text_prompt):]
68
- time.sleep(0.04)
69
- yield generated_text_without_prompt
70
 
71
 
72
  with gr.Blocks(css=CSS) as demo:
 
42
  if type(hist[0])==tuple:
43
  image = hist[0][0]
44
 
45
+ # if image is None:
46
+ # gr.Error("You need to upload an image for LLaVA to work.")
47
+ # prompt=f"<|start_header_id|>user<|end_header_id|>\n\n<image>\n{message['text']}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
48
+ # print(f"prompt: {prompt}")
49
+ # image = Image.open(image)
50
+ # inputs = processor(prompt, image, return_tensors='pt').to(0, torch.float16)
51
 
52
+ # streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True})
53
+ # generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
54
+ # generated_text = ""
55
 
56
+ # thread = Thread(target=model.generate, kwargs=generation_kwargs)
57
+ # thread.start()
58
 
59
+ # text_prompt =f"<|start_header_id|>user<|end_header_id|>\n\n{message['text']}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
60
+ # print(f"text_prompt: {text_prompt}")
61
 
62
+ # buffer = ""
63
+ # for new_text in streamer:
64
 
65
+ # buffer += new_text
66
 
67
+ # generated_text_without_prompt = buffer[len(text_prompt):]
68
+ # time.sleep(0.04)
69
+ # yield generated_text_without_prompt
70
 
71
 
72
  with gr.Blocks(css=CSS) as demo: