Offex commited on
Commit
fc2c793
·
verified ·
1 Parent(s): 85ebf4d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ import easyocr
5
+
6
+ # AI model load ho raha hai jo English text padhega
7
+ reader = easyocr.Reader(['en'], gpu=False)
8
+
9
+ def remove_text_from_image(img):
10
+ # Photo ko array me convert karna
11
+ img = np.array(img)
12
+
13
+ # Photo me text kahan hai, wo dhundhna
14
+ results = reader.readtext(img)
15
+
16
+ # Ek khali (black) mask banana
17
+ mask = np.zeros(img.shape[:2], dtype=np.uint8)
18
+
19
+ # Jahan text mila hai, wahan mask par safed (white) box banana
20
+ for (bbox, text, prob) in results:
21
+ (tl, tr, br, bl) = bbox
22
+ tl = (int(tl[0]), int(tl[1]))
23
+ br = (int(br[0]), int(br[1]))
24
+ cv2.rectangle(mask, tl, br, 255, -1)
25
+
26
+ # Text ke kinaro ko thoda bada karna taaki pura text cover ho jaye
27
+ kernel = np.ones((5,5), np.uint8)
28
+ mask = cv2.dilate(mask, kernel, iterations=1)
29
+
30
+ # Asli magic: Text ko hata kar background fill karna (Inpainting)
31
+ result = cv2.inpaint(img, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
32
+
33
+ return result
34
+
35
+ # Gradio ka User Interface (UI) banana
36
+ interface = gr.Interface(
37
+ fn=remove_text_from_image,
38
+ inputs=gr.Image(type="numpy", label="Upload Image (Text wali photo daalein)"),
39
+ outputs=gr.Image(type="numpy", label="Result (Bina text wali photo)"),
40
+ title="Hyco AI Text Remover",
41
+ description="Is tool me photo upload karein, aur AI automatically usme se captions aur text hata dega."
42
+ )
43
+
44
+ # App ko start karna
45
+ interface.launch()