free_blackjack / app.py
davidr99's picture
Update app.py
150bfad verified
raw
history blame
1.29 kB
import gradio as gr
import torch
import requests
from PIL import Image
from huggingface_hub import create_repo
from transformers import Trainer
from transformers import TrainingArguments
from transformers import PaliGemmaProcessor
from transformers import BitsAndBytesConfig
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
from huggingface_hub import whoami
model_id = "google/paligemma-3b-pt-224"
finetuned_model_id = "davidr99/finetuned_paligemma_blackjack"
import gradio as gr
model = processor = None
def blackjack_ai(image):
globals model, processor
if model == None:
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
processor = AutoProcessor.from_pretrained(model_id)
prompt = "<image><bos>extract json\n"
image_file = Image.fromarray(image.astype('uint8'), 'RGB')
inputs = processor(images=[image_file], text=prompt, return_tensors="pt")
output = model.generate(**inputs, max_new_tokens=125)
return processor.decode(output[0], skip_special_tokens=True)[14:]
with gr.Blocks() as demo:
gr.LoginButton()
image = gr.Image()
submit = gr.Button("Submit")
output = gr.TextArea()
submit.click(blackjack_ai, inputs=[image], outputs=[output])
demo.launch()