|
import gradio as gr |
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer |
|
from PIL import Image |
|
import pytesseract |
|
|
|
|
|
model_name = "quadranttechnologies/Receipt_Image_Analyzer" |
|
model = AutoModelForSequenceClassification.from_pretrained(model_name) |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
|
|
|
def analyze_receipt(image): |
|
|
|
extracted_text = pytesseract.image_to_string(image) |
|
|
|
|
|
inputs = tokenizer(extracted_text, return_tensors="pt", truncation=True, padding=True) |
|
|
|
|
|
outputs = model(**inputs) |
|
logits = outputs.logits |
|
predicted_class = logits.argmax(-1).item() |
|
|
|
|
|
result = { |
|
"extracted_text": extracted_text, |
|
"predicted_class": predicted_class |
|
} |
|
return result |
|
|
|
|
|
interface = gr.Interface( |
|
fn=analyze_receipt, |
|
inputs=gr.inputs.Image(type="pil"), |
|
outputs="json", |
|
title="Receipt Image Analyzer", |
|
description="Upload a receipt image to analyze and classify its contents.", |
|
) |
|
|
|
|
|
interface.launch() |
|
|