Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,8 @@ model.to("cuda:0")
|
|
| 31 |
|
| 32 |
@spaces.GPU
|
| 33 |
def bot_streaming(message, history):
|
| 34 |
-
print(message)
|
|
|
|
| 35 |
if message["files"]:
|
| 36 |
# message["files"][-1] is a Dict or just a string
|
| 37 |
if type(message["files"][-1]) == dict:
|
|
@@ -47,14 +48,12 @@ def bot_streaming(message, history):
|
|
| 47 |
try:
|
| 48 |
if image is None:
|
| 49 |
# Handle the case where image is None
|
| 50 |
-
gr.Error("You need to upload an image for
|
| 51 |
except NameError:
|
| 52 |
# Handle the case where 'image' is not defined at all
|
| 53 |
-
gr.Error("You need to upload an image for
|
| 54 |
|
| 55 |
-
|
| 56 |
-
prompt = f"""User:<image>\n{message} Falcon:"""
|
| 57 |
-
# print(f"prompt: {prompt}")
|
| 58 |
image = Image.open(image)
|
| 59 |
inputs = processor(prompt, image, return_tensors='pt').to(0, torch.float16)
|
| 60 |
|
|
@@ -64,23 +63,13 @@ def bot_streaming(message, history):
|
|
| 64 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
| 65 |
thread.start()
|
| 66 |
|
| 67 |
-
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"
|
| 68 |
-
# print(f"text_prompt: {text_prompt}")
|
| 69 |
-
|
| 70 |
buffer = ""
|
| 71 |
-
time.sleep(0.5)
|
| 72 |
for new_text in streamer:
|
| 73 |
# find <|eot_id|> and remove it from the new_text
|
| 74 |
if "<|eot_id|>" in new_text:
|
| 75 |
new_text = new_text.split("<|eot_id|>")[0]
|
| 76 |
buffer += new_text
|
| 77 |
-
|
| 78 |
-
# generated_text_without_prompt = buffer[len(text_prompt):]
|
| 79 |
-
generated_text_without_prompt = buffer
|
| 80 |
-
# print(generated_text_without_prompt)
|
| 81 |
-
time.sleep(0.06)
|
| 82 |
-
# print(f"new_text: {generated_text_without_prompt}")
|
| 83 |
-
yield generated_text_without_prompt
|
| 84 |
|
| 85 |
|
| 86 |
chatbot=gr.Chatbot(placeholder=PLACEHOLDER,scale=1)
|
|
@@ -99,5 +88,6 @@ with gr.Blocks(fill_height=True, ) as demo:
|
|
| 99 |
cache_examples=False,
|
| 100 |
)
|
| 101 |
|
| 102 |
-
demo.queue(
|
| 103 |
-
demo.launch(
|
|
|
|
|
|
| 31 |
|
| 32 |
@spaces.GPU
|
| 33 |
def bot_streaming(message, history):
|
| 34 |
+
print(f'message is - {message}')
|
| 35 |
+
print(f'history is - {history}')
|
| 36 |
if message["files"]:
|
| 37 |
# message["files"][-1] is a Dict or just a string
|
| 38 |
if type(message["files"][-1]) == dict:
|
|
|
|
| 48 |
try:
|
| 49 |
if image is None:
|
| 50 |
# Handle the case where image is None
|
| 51 |
+
gr.Error("You need to upload an image for FalconVLM to work.")
|
| 52 |
except NameError:
|
| 53 |
# Handle the case where 'image' is not defined at all
|
| 54 |
+
gr.Error("You need to upload an image for FalconVLM to work.")
|
| 55 |
|
| 56 |
+
prompt = f"""User:<image>\n{message['text']} Falcon:"""
|
|
|
|
|
|
|
| 57 |
image = Image.open(image)
|
| 58 |
inputs = processor(prompt, image, return_tensors='pt').to(0, torch.float16)
|
| 59 |
|
|
|
|
| 63 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
| 64 |
thread.start()
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
buffer = ""
|
|
|
|
| 67 |
for new_text in streamer:
|
| 68 |
# find <|eot_id|> and remove it from the new_text
|
| 69 |
if "<|eot_id|>" in new_text:
|
| 70 |
new_text = new_text.split("<|eot_id|>")[0]
|
| 71 |
buffer += new_text
|
| 72 |
+
yield buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
chatbot=gr.Chatbot(placeholder=PLACEHOLDER,scale=1)
|
|
|
|
| 88 |
cache_examples=False,
|
| 89 |
)
|
| 90 |
|
| 91 |
+
demo.queue()
|
| 92 |
+
demo.launch()
|
| 93 |
+
|