Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,27 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
labeled_output = {id2label[pred]: texts[i] for i, pred in enumerate(predictions) if pred != 4}
|
29 |
-
return labeled_output
|
30 |
-
|
31 |
-
interface = gr.Interface(
|
32 |
-
fn=predict_receipt,
|
33 |
-
inputs=gr.Image(type="pil"),
|
34 |
-
outputs="json",
|
35 |
-
title="Receipt Analyzer",
|
36 |
-
description="Upload a receipt image to extract key information."
|
37 |
-
)
|
38 |
-
|
39 |
-
if __name__ == "__main__":
|
40 |
-
interface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
|
4 |
+
# Load your fine-tuned model and tokenizer
|
5 |
+
model_name = "quadranttechnologies/Receipt_Image_Analyzer"
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define a prediction function
|
10 |
+
def analyze_receipt(receipt_text):
|
11 |
+
inputs = tokenizer(receipt_text, return_tensors="pt", truncation=True, padding=True)
|
12 |
+
outputs = model(**inputs)
|
13 |
+
logits = outputs.logits
|
14 |
+
predicted_class = logits.argmax(-1).item()
|
15 |
+
return f"Predicted Class: {predicted_class}"
|
16 |
+
|
17 |
+
# Create a Gradio interface
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=analyze_receipt,
|
20 |
+
inputs="text",
|
21 |
+
outputs="text",
|
22 |
+
title="Receipt Image Analyzer",
|
23 |
+
description="Analyze receipts for relevant information using a fine-tuned LLM model.",
|
24 |
+
)
|
25 |
+
|
26 |
+
# Launch the Gradio app
|
27 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|