Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,39 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import requests
|
4 |
|
5 |
+
from PIL import Image
|
6 |
+
from datasets import load_dataset
|
7 |
+
from peft import get_peft_model, LoraConfig
|
8 |
|
9 |
+
from huggingface_hub import create_repo
|
10 |
+
from transformers import Trainer
|
11 |
+
from transformers import TrainingArguments
|
12 |
+
from transformers import PaliGemmaProcessor
|
13 |
+
from transformers import BitsAndBytesConfig
|
14 |
+
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
15 |
+
|
16 |
+
model_id = "google/paligemma-3b-pt-224"
|
17 |
+
finetuned_model_id = "davidr99/finetuned_paligemma_blackjack"
|
18 |
+
|
19 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
|
20 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
21 |
+
|
22 |
+
import gradio as gr
|
23 |
+
|
24 |
+
|
25 |
+
def blackjack_ai(image):
|
26 |
+
prompt = "<image><bos>extract json\n"
|
27 |
+
image_file = Image.fromarray(image.astype('uint8'), 'RGB')
|
28 |
+
inputs = processor(images=[image_file], text=prompt, return_tensors="pt")
|
29 |
+
output = model.generate(**inputs, max_new_tokens=125)
|
30 |
+
return processor.decode(output[0], skip_special_tokens=True)[14:]
|
31 |
+
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
image = gr.Image()
|
34 |
+
submit = gr.Button("Submit")
|
35 |
+
output = gr.TextArea()
|
36 |
+
|
37 |
+
submit.click(blackjack_ai, inputs=[image], outputs=[output])
|
38 |
+
|
39 |
demo.launch()
|