remove additional inputs and output text from streamer
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ model = LlavaForConditionalGeneration.from_pretrained(
|
|
| 19 |
model_id,
|
| 20 |
torch_dtype=torch.float16,
|
| 21 |
low_cpu_mem_usage=True
|
| 22 |
-
).to('cuda')
|
| 23 |
|
| 24 |
processor = AutoProcessor.from_pretrained(model_id)
|
| 25 |
|
|
@@ -27,11 +27,7 @@ model.generation_config.eos_token_id = 128009
|
|
| 27 |
|
| 28 |
@spaces.GPU(duration=120)
|
| 29 |
def krypton(input,
|
| 30 |
-
history
|
| 31 |
-
max_new_tokens,
|
| 32 |
-
temperature,
|
| 33 |
-
num_beams,
|
| 34 |
-
do_sample: bool=True):
|
| 35 |
"""
|
| 36 |
Recieves inputs (prompts with images if they were added),
|
| 37 |
the image is formated for pil and prompt is formated for the model,
|
|
@@ -66,17 +62,12 @@ def krypton(input,
|
|
| 66 |
# Streamer
|
| 67 |
streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": False, "skip_prompt": True})
|
| 68 |
|
| 69 |
-
if temperature == 0.0:
|
| 70 |
-
do_sample = False
|
| 71 |
-
|
| 72 |
# Generation kwargs
|
| 73 |
generation_kwargs = dict(
|
| 74 |
inputs=inputs,
|
| 75 |
streamer=streamer,
|
| 76 |
-
max_new_tokens=
|
| 77 |
-
|
| 78 |
-
num_beams=num_beams,
|
| 79 |
-
do_sample=do_sample
|
| 80 |
)
|
| 81 |
|
| 82 |
thread = threading.Thread(target=model.generate, kwargs=generation_kwargs)
|
|
@@ -105,27 +96,27 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 105 |
fn=krypton,
|
| 106 |
chatbot=chatbot,
|
| 107 |
fill_height=True,
|
| 108 |
-
additional_inputs_accordion=gr.Accordion(label="βοΈ Parameters", open=False, render=False),
|
| 109 |
-
additional_inputs=[
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
],
|
| 129 |
multimodal=True,
|
| 130 |
textbox=chat_input,
|
| 131 |
)
|
|
|
|
| 19 |
model_id,
|
| 20 |
torch_dtype=torch.float16,
|
| 21 |
low_cpu_mem_usage=True
|
| 22 |
+
).to('cuda:0')
|
| 23 |
|
| 24 |
processor = AutoProcessor.from_pretrained(model_id)
|
| 25 |
|
|
|
|
| 27 |
|
| 28 |
@spaces.GPU(duration=120)
|
| 29 |
def krypton(input,
|
| 30 |
+
history):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
"""
|
| 32 |
Recieves inputs (prompts with images if they were added),
|
| 33 |
the image is formated for pil and prompt is formated for the model,
|
|
|
|
| 62 |
# Streamer
|
| 63 |
streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": False, "skip_prompt": True})
|
| 64 |
|
|
|
|
|
|
|
|
|
|
| 65 |
# Generation kwargs
|
| 66 |
generation_kwargs = dict(
|
| 67 |
inputs=inputs,
|
| 68 |
streamer=streamer,
|
| 69 |
+
max_new_tokens=1024,
|
| 70 |
+
do_sample=False
|
|
|
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
thread = threading.Thread(target=model.generate, kwargs=generation_kwargs)
|
|
|
|
| 96 |
fn=krypton,
|
| 97 |
chatbot=chatbot,
|
| 98 |
fill_height=True,
|
| 99 |
+
# additional_inputs_accordion=gr.Accordion(label="βοΈ Parameters", open=False, render=False),
|
| 100 |
+
# additional_inputs=[
|
| 101 |
+
# gr.Slider(minimum=20,
|
| 102 |
+
# maximum=80,
|
| 103 |
+
# step=1,
|
| 104 |
+
# value=50,
|
| 105 |
+
# label="Max New Tokens",
|
| 106 |
+
# render=False),
|
| 107 |
+
# gr.Slider(minimum=0.0,
|
| 108 |
+
# maximum=1.0,
|
| 109 |
+
# step=0.1,
|
| 110 |
+
# value=0.7,
|
| 111 |
+
# label="Temperature",
|
| 112 |
+
# render=False),
|
| 113 |
+
# gr.Slider(minimum=1,
|
| 114 |
+
# maximum=12,
|
| 115 |
+
# step=1,
|
| 116 |
+
# value=5,
|
| 117 |
+
# label="Number of Beams",
|
| 118 |
+
# render=False),
|
| 119 |
+
# ],
|
| 120 |
multimodal=True,
|
| 121 |
textbox=chat_input,
|
| 122 |
)
|