Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,13 +51,11 @@ def process_image_and_text(image_pil, num_beams, temperature, seed):
|
|
| 51 |
device, dtype=torch.bfloat16
|
| 52 |
)
|
| 53 |
input_len = model_inputs["input_ids"].shape[-1]
|
| 54 |
-
|
| 55 |
-
# Set random seed for reproducibility
|
| 56 |
-
if seed is not None:
|
| 57 |
-
torch.manual_seed(int(seed))
|
| 58 |
|
| 59 |
with torch.inference_mode():
|
| 60 |
-
generation = model.generate(**model_inputs, max_new_tokens=
|
| 61 |
generation = generation[0][input_len:]
|
| 62 |
decoded = processor.decode(generation, skip_special_tokens=True)
|
| 63 |
|
|
@@ -74,10 +72,10 @@ if __name__ == "__main__":
|
|
| 74 |
gr.Image(type="pil", label="Upload an image"),
|
| 75 |
gr.Slider(minimum=1, maximum=10, step=1, value=1, label="Number of Beams"),
|
| 76 |
gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Temperature"),
|
| 77 |
-
gr.Number(label="Random Seed", value=
|
| 78 |
],
|
| 79 |
outputs=gr.Textbox(label="Generated Text"),
|
| 80 |
-
title="PaliGemma2 Image to Text",
|
| 81 |
description="Upload an image and enter a text prompt. The model will generate text based on both.",
|
| 82 |
)
|
| 83 |
iface.launch()
|
|
|
|
| 51 |
device, dtype=torch.bfloat16
|
| 52 |
)
|
| 53 |
input_len = model_inputs["input_ids"].shape[-1]
|
| 54 |
+
|
| 55 |
+
torch.manual_seed(seed) # Set random seed for reproducibility
|
|
|
|
|
|
|
| 56 |
|
| 57 |
with torch.inference_mode():
|
| 58 |
+
generation = model.generate(**model_inputs, max_new_tokens=100, do_sample=True, num_beams=num_beams, temperature=temperature)
|
| 59 |
generation = generation[0][input_len:]
|
| 60 |
decoded = processor.decode(generation, skip_special_tokens=True)
|
| 61 |
|
|
|
|
| 72 |
gr.Image(type="pil", label="Upload an image"),
|
| 73 |
gr.Slider(minimum=1, maximum=10, step=1, value=1, label="Number of Beams"),
|
| 74 |
gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Temperature"),
|
| 75 |
+
gr.Number(label="Random Seed", value=0, precision=0),
|
| 76 |
],
|
| 77 |
outputs=gr.Textbox(label="Generated Text"),
|
| 78 |
+
title="PaliGemma2 Image and Text to Text",
|
| 79 |
description="Upload an image and enter a text prompt. The model will generate text based on both.",
|
| 80 |
)
|
| 81 |
iface.launch()
|