Commit
•
ee9e2f0
1
Parent(s):
bc904d0
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,8 @@ DESCRIPTION = "# InstructBLIP"
|
|
14 |
|
15 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1024"))
|
16 |
|
|
|
|
|
17 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
18 |
|
19 |
model_id = "Salesforce/instructblip-vicuna-7b"
|
@@ -23,6 +25,7 @@ model = InstructBlipForConditionalGeneration.from_pretrained(model_id, torch_dty
|
|
23 |
|
24 |
@spaces.GPU
|
25 |
def run(
|
|
|
26 |
image: PIL.Image.Image,
|
27 |
prompt: str,
|
28 |
text_decoding_method: str = "Nucleus sampling",
|
@@ -34,6 +37,10 @@ def run(
|
|
34 |
length_penalty: float = 1.0,
|
35 |
temperature: float = 1.0,
|
36 |
) -> str:
|
|
|
|
|
|
|
|
|
37 |
h, w = image.size
|
38 |
scale = MAX_IMAGE_SIZE / max(h, w)
|
39 |
if scale < 1:
|
@@ -62,6 +69,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
62 |
|
63 |
with gr.Row():
|
64 |
with gr.Column():
|
|
|
65 |
input_image = gr.Image(type="pil")
|
66 |
prompt = gr.Textbox(label="Prompt")
|
67 |
run_button = gr.Button()
|
@@ -131,6 +139,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
131 |
triggers=[prompt.submit, run_button.click],
|
132 |
fn=run,
|
133 |
inputs=[
|
|
|
134 |
input_image,
|
135 |
prompt,
|
136 |
text_decoding_method,
|
|
|
14 |
|
15 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1024"))
|
16 |
|
17 |
+
SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
|
18 |
+
|
19 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
20 |
|
21 |
model_id = "Salesforce/instructblip-vicuna-7b"
|
|
|
25 |
|
26 |
@spaces.GPU
|
27 |
def run(
|
28 |
+
secret_token: str,
|
29 |
image: PIL.Image.Image,
|
30 |
prompt: str,
|
31 |
text_decoding_method: str = "Nucleus sampling",
|
|
|
37 |
length_penalty: float = 1.0,
|
38 |
temperature: float = 1.0,
|
39 |
) -> str:
|
40 |
+
if secret_token != SECRET_TOKEN:
|
41 |
+
raise gr.Error(
|
42 |
+
f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
|
43 |
+
|
44 |
h, w = image.size
|
45 |
scale = MAX_IMAGE_SIZE / max(h, w)
|
46 |
if scale < 1:
|
|
|
69 |
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
+
secret_token = gr.Textbox(label="Secret token")
|
73 |
input_image = gr.Image(type="pil")
|
74 |
prompt = gr.Textbox(label="Prompt")
|
75 |
run_button = gr.Button()
|
|
|
139 |
triggers=[prompt.submit, run_button.click],
|
140 |
fn=run,
|
141 |
inputs=[
|
142 |
+
secret_token,
|
143 |
input_image,
|
144 |
prompt,
|
145 |
text_decoding_method,
|