Spaces:
Running
on
Zero
Running
on
Zero
don't stream text
Browse files
app.py
CHANGED
@@ -7,8 +7,8 @@ from transformers import TextIteratorStreamer, AutoTokenizer, AutoModelForCausal
|
|
7 |
from PIL import ImageDraw
|
8 |
from torchvision.transforms.v2 import Resize
|
9 |
|
10 |
-
|
11 |
-
|
12 |
|
13 |
model_id = "vikhyatk/moondream2"
|
14 |
revision = "2024-05-20"
|
@@ -39,7 +39,11 @@ def answer_question(img, prompt):
|
|
39 |
buffer = ""
|
40 |
for new_text in streamer:
|
41 |
buffer += new_text
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
|
44 |
def extract_floats(text):
|
45 |
# Regular expression to match an array of four floating point numbers
|
@@ -58,18 +62,18 @@ def extract_bbox(text):
|
|
58 |
bbox = (x1, y1, x2, y2)
|
59 |
return bbox
|
60 |
|
61 |
-
def process_answer(img, answer):
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
|
73 |
|
74 |
with gr.Blocks() as demo:
|
75 |
gr.Markdown(
|
@@ -89,6 +93,6 @@ with gr.Blocks() as demo:
|
|
89 |
|
90 |
submit.click(answer_question, [img, prompt], output)
|
91 |
prompt.submit(answer_question, [img, prompt], output)
|
92 |
-
output.change(process_answer, [img, output], ann, show_progress=False)
|
93 |
|
94 |
demo.queue().launch()
|
|
|
7 |
from PIL import ImageDraw
|
8 |
from torchvision.transforms.v2 import Resize
|
9 |
|
10 |
+
import subprocess
|
11 |
+
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
12 |
|
13 |
model_id = "vikhyatk/moondream2"
|
14 |
revision = "2024-05-20"
|
|
|
39 |
buffer = ""
|
40 |
for new_text in streamer:
|
41 |
buffer += new_text
|
42 |
+
|
43 |
+
# Wait for the thread to finish
|
44 |
+
thread.join()
|
45 |
+
|
46 |
+
return buffer.strip()
|
47 |
|
48 |
def extract_floats(text):
|
49 |
# Regular expression to match an array of four floating point numbers
|
|
|
62 |
bbox = (x1, y1, x2, y2)
|
63 |
return bbox
|
64 |
|
65 |
+
# def process_answer(img, answer):
|
66 |
+
# if extract_bbox(answer) is not None:
|
67 |
+
# x1, y1, x2, y2 = extract_bbox(answer)
|
68 |
+
# draw_image = Resize(768)(img)
|
69 |
+
# width, height = draw_image.size
|
70 |
+
# x1, x2 = int(x1 * width), int(x2 * width)
|
71 |
+
# y1, y2 = int(y1 * height), int(y2 * height)
|
72 |
+
# bbox = (x1, y1, x2, y2)
|
73 |
+
# ImageDraw.Draw(draw_image).rectangle(bbox, outline="red", width=3)
|
74 |
+
# return gr.update(visible=True, value=draw_image)
|
75 |
|
76 |
+
# return gr.update(visible=False, value=None)
|
77 |
|
78 |
with gr.Blocks() as demo:
|
79 |
gr.Markdown(
|
|
|
93 |
|
94 |
submit.click(answer_question, [img, prompt], output)
|
95 |
prompt.submit(answer_question, [img, prompt], output)
|
96 |
+
# output.change(process_answer, [img, output], ann, show_progress=False)
|
97 |
|
98 |
demo.queue().launch()
|