littlebylittle commited on
Commit
36e60fa
·
verified ·
1 Parent(s): 7f2bf95

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -41
app.py DELETED
@@ -1,41 +0,0 @@
1
- import gradio as gr
2
- from transformers import TrOCRProcessor, VisionEncoderDecoderModel
3
- from PIL import Image
4
- import torch
5
-
6
- # Path to the model folder bundled inside this Space.
7
- # Upload the full contents of your saved model directory
8
- # (the one you got from model.save_pretrained(...) / processor.save_pretrained(...)
9
- # in Week 4) into a folder here called "model" so this path resolves.
10
- MODEL_PATH = "./model"
11
-
12
- processor = TrOCRProcessor.from_pretrained(MODEL_PATH)
13
- model = VisionEncoderDecoderModel.from_pretrained(MODEL_PATH)
14
- model.eval()
15
-
16
-
17
- def extract_urdu_text(image):
18
- """Takes an image, returns extracted Urdu text."""
19
- if image is None:
20
- return "Please upload an image"
21
-
22
- pixel_values = processor(image, return_tensors="pt").pixel_values
23
- with torch.no_grad():
24
- generated_ids = model.generate(pixel_values, max_new_tokens=128)
25
- text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
26
-
27
- return text if text.strip() else "Could not extract text from this image"
28
-
29
-
30
- interface = gr.Interface(
31
- fn=extract_urdu_text,
32
- inputs=gr.Image(type="pil", label="Upload Urdu Image"),
33
- outputs=gr.Textbox(label="Extracted Urdu Text"),
34
- title="Urdu OCR -- Code Saviours SI-26",
35
- description="Upload an image containing Urdu text and get the extracted text.",
36
- examples=[],
37
- )
38
-
39
- if __name__ == "__main__":
40
- # On Spaces you don't need share=True -- Spaces already gives you a public URL.
41
- interface.launch()