Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
print("Loading model...")
|
| 7 |
+
model = T5ForConditionalGeneration.from_pretrained("younsmirzai/stackadvisor-extractor")
|
| 8 |
+
tokenizer = T5Tokenizer.from_pretrained("younsmirzai/stackadvisor-extractor")
|
| 9 |
+
print("✅ Model loaded!")
|
| 10 |
+
|
| 11 |
+
def extract_order(ocr_text):
|
| 12 |
+
if not ocr_text.strip():
|
| 13 |
+
return "Error: Empty input"
|
| 14 |
+
|
| 15 |
+
inputs = tokenizer(ocr_text, return_tensors="pt", max_length=256, truncation=True)
|
| 16 |
+
outputs = model.generate(**inputs, max_length=128)
|
| 17 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
return result
|
| 19 |
+
|
| 20 |
+
# Create Gradio interface
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=extract_order,
|
| 23 |
+
inputs=gr.Textbox(label="OCR Text", lines=5, placeholder="Paste OCR text here..."),
|
| 24 |
+
outputs=gr.Textbox(label="Extracted Order"),
|
| 25 |
+
title="StackAdvisor Order Extractor",
|
| 26 |
+
description="Extract delivery order info from OCR text"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|