MaziyarPanahi commited on
Commit
3086334
1 Parent(s): 58cf028

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -29,17 +29,15 @@ model.generation_config.eos_token_id = 128009
29
 
30
  @spaces.GPU
31
  def bot_streaming(message, history):
32
- print(message)
33
- if message["files"]:
34
- image = message["files"][-1]["path"]
35
- else:
36
- # if there's no image uploaded for this turn, look for images in the past turns
37
- # kept inside tuples, take the last one
38
- for hist in history:
39
- if type(hist[0])==tuple:
40
- image = hist[0][0]
41
-
42
-
43
  try:
44
  if image is None:
45
  # Handle the case where image is None
@@ -56,20 +54,20 @@ def bot_streaming(message, history):
56
  streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True})
57
  generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
58
  generated_text = ""
59
-
60
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
61
  thread.start()
62
 
63
  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"
64
  print(f"text_prompt: {text_prompt}")
65
-
66
  buffer = ""
67
  for new_text in streamer:
68
 
69
  buffer += new_text
70
 
71
  generated_text_without_prompt = buffer[len(text_prompt):]
72
- time.sleep(0.04)
73
  yield generated_text_without_prompt
74
 
75
 
@@ -78,5 +76,5 @@ demo = gr.ChatInterface(fn=bot_streaming, css=CSS, fill_height=True, title="LLaV
78
  description="Try [LLaVA Llama-3-8B](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers). Upload an image and start chatting about it, or simply try one of the examples below. If you don't upload an image, you will receive an error.",
79
  stop_btn="Stop Generation", multimodal=True)
80
 
81
- demo.queue(default_concurrency_limit=20, max_size=20, api_open=False)
82
  demo.launch(show_api=False, share=False)
 
29
 
30
  @spaces.GPU
31
  def bot_streaming(message, history):
32
+ print(message)
33
+ if message["files"]:
34
+ image = message["files"][-1]["path"]
35
+ else:
36
+ # if there's no image uploaded for this turn, look for images in the past turns
37
+ # kept inside tuples, take the last one
38
+ for hist in history:
39
+ if type(hist[0])==tuple:
40
+ image = hist[0][0]
 
 
41
  try:
42
  if image is None:
43
  # Handle the case where image is None
 
54
  streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True})
55
  generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
56
  generated_text = ""
57
+
58
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
59
  thread.start()
60
 
61
  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"
62
  print(f"text_prompt: {text_prompt}")
63
+
64
  buffer = ""
65
  for new_text in streamer:
66
 
67
  buffer += new_text
68
 
69
  generated_text_without_prompt = buffer[len(text_prompt):]
70
+ time.sleep(0.08)
71
  yield generated_text_without_prompt
72
 
73
 
 
76
  description="Try [LLaVA Llama-3-8B](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers). Upload an image and start chatting about it, or simply try one of the examples below. If you don't upload an image, you will receive an error.",
77
  stop_btn="Stop Generation", multimodal=True)
78
 
79
+ demo.queue(api_open=False)
80
  demo.launch(show_api=False, share=False)