Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,16 +11,24 @@ from transformers import PaliGemmaProcessor
|
|
11 |
from transformers import BitsAndBytesConfig
|
12 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
13 |
|
|
|
|
|
|
|
14 |
model_id = "google/paligemma-3b-pt-224"
|
15 |
finetuned_model_id = "davidr99/finetuned_paligemma_blackjack"
|
16 |
|
17 |
-
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
|
18 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
19 |
-
|
20 |
import gradio as gr
|
21 |
|
|
|
|
|
22 |
|
23 |
def blackjack_ai(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
prompt = "<image><bos>extract json\n"
|
25 |
image_file = Image.fromarray(image.astype('uint8'), 'RGB')
|
26 |
inputs = processor(images=[image_file], text=prompt, return_tensors="pt")
|
@@ -28,6 +36,8 @@ def blackjack_ai(image):
|
|
28 |
return processor.decode(output[0], skip_special_tokens=True)[14:]
|
29 |
|
30 |
with gr.Blocks() as demo:
|
|
|
|
|
31 |
image = gr.Image()
|
32 |
submit = gr.Button("Submit")
|
33 |
output = gr.TextArea()
|
|
|
11 |
from transformers import BitsAndBytesConfig
|
12 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
13 |
|
14 |
+
from huggingface_hub import whoami
|
15 |
+
|
16 |
+
|
17 |
model_id = "google/paligemma-3b-pt-224"
|
18 |
finetuned_model_id = "davidr99/finetuned_paligemma_blackjack"
|
19 |
|
|
|
|
|
|
|
20 |
import gradio as gr
|
21 |
|
22 |
+
model = processor = None
|
23 |
+
|
24 |
|
25 |
def blackjack_ai(image):
|
26 |
+
globals model, processor
|
27 |
+
|
28 |
+
if model == None:
|
29 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
|
30 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
31 |
+
|
32 |
prompt = "<image><bos>extract json\n"
|
33 |
image_file = Image.fromarray(image.astype('uint8'), 'RGB')
|
34 |
inputs = processor(images=[image_file], text=prompt, return_tensors="pt")
|
|
|
36 |
return processor.decode(output[0], skip_special_tokens=True)[14:]
|
37 |
|
38 |
with gr.Blocks() as demo:
|
39 |
+
gr.LoginButton()
|
40 |
+
|
41 |
image = gr.Image()
|
42 |
submit = gr.Button("Submit")
|
43 |
output = gr.TextArea()
|